I'm exploring the Python multiprocessing module and don't understand why the following code does not print anything at all. Without the while-loop the program prints Worker_1 as expected.
import multiprocessing, time
def worker1():
print 'Worker_1'
while 1:
print 'Worker_1'
time.sleep(3)
return
if __name__ == '__main__':
jobs = []
p = multiprocessing.Process(target=worker1)
jobs.append(p)
p.start()
On my system (Python 2.6&2.7 on Linux), this works as expected. Which platform are you using? On some platforms(Windows), fork
hast to be emulated by creating a totally new process and setting it up. I suspect some stdout
is not transferred to the child process. Try:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With