Search code examples
pythonmultiprocessingpid

Multiprocessing output to file


Is there a way to redirect the stream to file when creating an instance of class Process or during execution Process(target=..., args=(...)).start()

I asked about the typical pythonic way

Process(target=start_test, args=(timestamp,current_test_suite,user_ip)).start()

If there is no pythonic way to do that maybe linux can redirect PID output to file?


Solution

  • If we want to redirect Process output to file we have to assign sys.stdout to open(filename,'w') or open(filename,'a') if we want to appending our log file.