基本的并行python程序在Windows上冻结 [英] Basic parallel python program freezes on Windows

查看:85
本文介绍了基本的并行python程序在Windows上冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是来自 https://的基本Python示例docs.python.org/2/library/multiprocessing.html#module-multiprocessing.pool 关于并行处理

from multiprocessing import Pool

def f(x):
    return x*x

if __name__ == '__main__':
    p = Pool(5)
    print(p.map(f, [1, 2, 3]))

由于某种原因我无法在我的PC上运行它.当我尝试执行第三个程序块时,程序冻结.我的操作系统是Windows10.我在Spyder IDE上运行该程序,并且安装了anaconda.可能是什么问题?

which I can't run for some reason on my PC. When I try to execute the third block the program freezes. My OS is Windows 10. I run the program on the Spyder IDE and I have an anaconda installation. What is possibly the problem?

推荐答案

这是Windows用户遇到的问题,与anaconda环境无关.我找到了解决方案.首先,您必须创建另一个.py文件以保存f(x)函数.然后导入您创建的函数,程序将平稳运行.

This is a problem Windows users have and it is not relevant to the anaconda environment. I found the solution. Firstly you have to create another .py file in order to save the f(x) function. Then you import the function you have created and the program runs smoothly.

这篇关于基本的并行python程序在Windows上冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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