Python创意机盖:多重处理无法正常工作 [英] Python Enthought Canopy: multiprocessing not working

查看:45
本文介绍了Python创意机盖:多重处理无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用带有思想的顶篷(Windows 8)进行多处理.我尝试了以下示例:

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".

我从Canopy(我认为是IDLE)提供的环境中运行文件(main.py),但是我没有在解释器中复制这些行,而是运行了整个脚本(例如%run"D:/path/main .py)

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

我在做什么错了?

推荐答案

Canopy的python shell是IPython的QtConsole(不是IDLE).

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

QtConsole将计算结果与控制台输出(前端)分开.为确保在需要时打印文本,请在打印语句后插入该文本:

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

这篇关于Python创意机盖:多重处理无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆