No print output from child multiprocessing.Process unless the program crashes
-
21-08-2019 - |
Question
I am having trouble with the Python multiprocessing module. I am using the Process
class to spawn a new process in order to utilize my second core. This second process loads a bunch of data into RAM and then waits patiently instead of consuming.
I wanted to see what that process printed with the print
command, however, I do not see anything that it prints. I only see what the parent process prints. Now this makes sense to me since they live in two different process. The second process doesn't spawn its own shell/standard output window, nor is its output sent to the parent. Yet when this process crashs, it prints everything that my script told it to print, plus the stack trace and error.
I am wondering if there is a simple way to send the child process's print output to the first process, or have it spawn a shell/standard output so that I may debug it. I know I could create a multiprocessing.Queue
dedicated to transmitting prints to the parent so that it may print these to standard output, but I do not feel like doing this if a simpler solution exists.
Solution
Have you tried flushing stdout?
import sys
print "foo"
sys.stdout.flush()