Why Does My Print Function (in Multiprocessing) Print Nothing?
why does my print function (in python multiprocess) print nothing? from multiprocessing import Process, Queue import os, time, random def write(q): print('Process to write: %
Solution 1:
The multiprocessing module uses fork to spawn child processes for parallelism. Windows does not implement fork, and Python emulation of it on Windows is incomplete. One of the missing effects is that stdout
(used by print()
) is not inherited by the child processes. Rather, child processes use the default stdout
.
This works fine in a command window because it uses default stdout
. This shows nothing in Spyder because a different pipe is used for output to the Spyder IPython console window.
See this question ("Simple Multiprocessing function in Spyder doesn't output results") and this answer for additional details and potential mitigations.
Post a Comment for "Why Does My Print Function (in Multiprocessing) Print Nothing?"