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()
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:
fork
stdout
IDLE? , . , , Linux ( "Worker_1" 3 ). IDLE, . , p.join(), , . -, p.join() Linux, .
p.join()
p.join() IDLE script , . , , - , IDLE stdout idlelib.rpc.RPCProxy. , , IDLE, .