Python multiprocessing: no output with while-loop in working function

I am studying the Python multiprocessing module and do not understand why the following code does not print anything. Without a 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()
+5
source share
2 answers

On my system (Python 2.6 and 2.7 on Linux), this works as expected. What platform are you using? On some platforms (Windows), forkyou need to emulate by creating a completely new process and customizing it. I suspect that some are stdoutnot passed to the child process. Try:

  • Threading module . This is enough if you just want to wait for the event in the stream.
  • , POSIX, BSD, Linux Solaris
+2

IDLE? , . , , Linux ( "Worker_1" 3 ). IDLE, . , p.join(), , . -, p.join() Linux, .

p.join() IDLE script , . , , - , IDLE stdout idlelib.rpc.RPCProxy. , , IDLE, .

0

All Articles