How do you capture the stdout/stderr of a specific target of a process launched from Python's mulitprocessing.Process
library, ideally without requiring special modifications to the target function?
e.g.
p = Process(target=myfunc)
p.daemon=True
p.start()
p.join()
print p.exitcode, p.stderr.getvalue()
I know how to override sys.stdout/sys.stderr with a custom file object and use multiprocessing.Queue to redirect IO between processes, but this requires modifying the target function to write its output to the Queue.
Is something like this available with Process
? I'm assuming it is on some level, since I'm able to see the process's output in the terminal when running, even if I can't record it from the parent process.