找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2757|回复: 0

[求助] multiprocessing子进程不运行

1

主题

2

帖子

2

积分

贫民

积分
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.


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表