报错内容如下:

    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.

根据报错提示可知:

           没有在模块中使用

        if __name__ == '__main__':
                   freeze_support()

      如果程序需要,可以省略“freeze_support()”行

更改代码如下:可以正常运行

# 进程
from multiprocessing import Process

def foo(i):
    print(" This is Process ", i)

def main():   
    for i in range(5):
        p=Process(target=foo, args=(i, ))
        p.start()
    
if __name__ == '__main__':
    main() 

输出结果:

               This is Process  1
               This is Process  0
               This is Process  2
               This is Process  3
               This is Process  4  

 

 

 

更多推荐

启动进程报错 RuntimeError: An attempt has been made to start a new process before the