There are only two things that I would add to @Mark Rushakoff's answer. When debugging, it was very useful for me to change the buffering parameter of my open() calls to 0.
sys.stdout = open(str(os.getpid()) + ".out", "a", buffering=0)
Otherwise, madness , because when tail -f outputs the output file, the results may be erratic. buffering=0 for tail -f excellent.
And for completeness, do yourself a favor and redirect sys.stderr .
sys.stderr = open(str(os.getpid()) + "_error.out", "a", buffering=0)
In addition, for convenience, you can dump it into a separate process class, if you want,
class MyProc(Process): def run(self):
Makes sense
HeyWatchThis May 29 '14 at 15:51 2014-05-29 15:51
source share