views:

120

answers:

1

Problem:

I have a monitor program in Python that uses subprocess' Popen to start new processes. These processes have the potential to run for a very long time (weeks-months). I'm passing a file handle to stdout variable in Popen and I'm worried that this file will get huge easily. Is there a way I can safely move or remove the data in that log file?

Important Note: This is on a windows system so any solution has to be compatible with windows.

Code Snippet:

This is how I create the process.

try:
    logFile = file(self.logFileName, 'w')
    self.process = Popen(self.command, shell=False, stdout=logFile, stderr=STDOUT)
finally:
    logFile.close()
+1  A: 

Fix the monitor program so that it is responsible for rotating its own logs, or mediate the data coming from the log program yourself and package it out into separate files.

Those are the two options you have. You can't mess with another process' file descriptors once it's running, so no, you can't "move or remove the data" in that file.

= Mike

Its not the answer I was hoping for, but it looks like you're right.
Robbie