首页
Python中文网
在线手册
Python入门
Linux教程
Python高级教程
登录
注册
用户名
Email
自动登录
找回密码
密码
登录
立即注册
扫一扫,访问微社区
只需一步,快速开始
论坛
BBS
Python教程
在线手册
Python入门
Linux教程
Python高级教程
Python函数详解
搜索
本版
帖子
用户
道具
勋章
任务
设置
退出
Python论坛 - 国内最好的Python中文社区
»
论坛
›
技术交流
›
python问答 - 求助悬赏区 Help!
›
multiprocessing子进程不运行
返回列表
查看:
2757
|
回复:
0
[求助]
multiprocessing子进程不运行
mjjiaqian
当前离线
积分
2
1
主题
2
帖子
2
积分
贫民
贫民, 积分 2, 距离下一级还需 58 积分
贫民, 积分 2, 距离下一级还需 58 积分
积分
2
发消息
mjjiaqian
发表于 2022-9-19 15:46:25
|
显示全部楼层
|
阅读模式
2
威望
拜托哪位大神帮帮忙吧,多进程搞了好几天也不行,求求了,呜哇哇哇
windows系统,spyder,运行也不报错,但是子进程根本没有结果,直接复制的别人的代码也不行,
代码如下:
from multiprocessing import Process
def fun1(name):
print('测试%s多进程' %name)
if __name__ == '__main__':
process_list = []
for i in range(5): #开启5个子进程执行fun1函数
p = Process(target=fun1,args=('Python',)) #实例化进程对象
p.start()
process_list.append(p)
for i in process_list:
p.join()
print('结束测试')
运行结果
:
runfile('D:/data/pythonProject/yzh/untitled2.py', wdir='D:/data/pythonProject/yzh')
结束测试
在c**ole运行就会出现:
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 idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
我来回答
回复
使用道具
举报
返回列表
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
立即注册
本版积分规则
发表回复
回帖后跳转到最后一页
快速回复
返回顶部
返回列表