python:multiprocessing 在windows中的使用:RuntimeError:
来源:互联网 发布:横县教研室网络硬盘 编辑:程序博客网 时间:2024/05/29 14:25
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiomin the main module:
multiprocessing的使用在Linux和mac中直接使用即可,但是在window中不太一样
python-2.7-docs-html/library/multiprocessing.html#multiprocessing-programming
简而言之,需要在p=Process()前加上
if __name__ == ‘__main__’:
p = Process(...
Safe importing of main module
Make sure that the main module can be safely imported by a new Python interpreter without causing unintended side effects (such a starting a new process).
For example, under Windows running the following module would fail with a RuntimeError:
from multiprocessing import Process
def foo():
print 'hello'
p = Process(target=foo)
p.start()
Instead one should protect the “entry point” of the program by using if __name__ == '__main__': as follows:
from multiprocessing import Process, freeze_support
def foo():
print 'hello'
if __name__ == '__main__':
freeze_support()
p = Process(target=foo)
p.start()
(The freeze_support() line can be omitted if the program will be run normally instead of frozen.)
This allows the newly spawned Python interpreter to safely import the module and then run the module’s foo() function.
from multiprocessing import Process#window不可以用fork(),但是可以用multiprocessing,可以跨平台使用import timedef test():print("hello")if __name__=='__main__':#freeze__support()p=Process(target=test)p.start()#所有的进程结束后,程序才结束
阅读全文
0 0
- python:multiprocessing 在windows中的使用:RuntimeError:
- deepwalk遇到RuntimeError on windows trying python multiprocessing问题解决办法
- multiprocessing在python中的高级应用-进程
- python(二):使用multiprocessing中的常见问题
- python多线程multiprocessing使用
- multiprocessing在python中的高级应用-IPC 之 Queue
- multiprocessing在python中的高级应用-IPC 之 Pipe
- multiprocessing在python中的高级应用-进程池
- multiprocessing在python中的高级应用-共享数据与同步
- multiprocessing在python中的高级应用-托管对象
- python 2.6 multiprocessing 的使用
- python基础:multiprocessing的使用
- python multiprocessing dummy Pool 使用
- 关于python中的多进程模块multiprocessing
- python multiprocessing
- python multiprocessing
- Python--multiprocessing
- python multiprocessing
- 慎用多继承
- 判断相似三角形
- 欢迎使用CSDN-markdown编辑器
- 算法题目---二叉搜索树与双向链表
- 谈谈链表
- python:multiprocessing 在windows中的使用:RuntimeError:
- 修改tomcat默认端口
- Spring框架
- 16
- mysql破解密码并修改密码
- Fragment 使用add 和 hide 生命周期
- 17
- jquery广告弹出
- Date类问题1