Popen log management question

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()

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

链接地址: http://www.djcxy.com/p/77128.html

上一篇: Python子流程/ Popen与修改后的环境

下一篇: Popen日志管理问题