Python Enthought Canopy: multiprocessing not working

ε祈祈猫儿з 提交于 2019-12-01 13:29:28

问题


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:


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()


来源:https://stackoverflow.com/questions/25925399/python-enthought-canopy-multiprocessing-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!