Open kylemcdonald opened 5 years ago
It will not work because a new process forks from the existing one. It will execute again all lines, including imports and "tp = TraceProfiler(output=open('trace.out', 'w'))" But the file "trace.out" is already opened for writing by the main process, so this line will fail.
In addition, even if you comment lines related to TraceProfiler, the code will fail. The second process will execute "worker = Process(target=job)", thus opening the 3rd process. The 3rd process will open 4th process, etc. It's essentially a fork bomb.
When working with multiple processes it's important to use "if name == 'main':". This LOC will ensure that only main process executes the main program logic.
Testing the threading behavior, it seems to work:
Output:
Changing the one line to
worker = Process(target=job)
I get very long output that catches the Process being created and joined, but doesn't see anything inside. My current solution is to create a pytracing object for each Process, and then I'm going to try and rename/munge and concatenate the traces: