Python Enthought Canopy: multiprocessing not worki

2019-02-21 06:21发布

I've been trying multiprocessing with enthought canopy (Windows 8). I tried the following example:

import multiprocessing

nProcesses=3

def worker():
   """worker function"""
    print "working"
    return

if __name__ == '__main__':
 jobs = []
 for i in range(nProcesses):
     p = multiprocessing.Process(target=worker)
     jobs.append(p)
     p.start()

close to a copypaste of examples you find online...

The processes are created but seem to do nothing. No printing of "working".

I run my file (main.py) from the environment provided by Canopy (IDLE I think) but I do not copy those lines in the interpreter, I run the whole script (like %run "D:/path/main.py")

What am I doing wrong?

1条回答
闹够了就滚
2楼-- · 2019-02-21 06:31

Canopy's python shell is IPython's QtConsole (not IDLE).

QtConsole separates the calculations from the console output (front end). To ensure that text is printed when you want, insert this after your print statement:

sys.stdout.flush()
查看更多
登录 后发表回答