|
20鱼币
程序不会进入Process中,命令行运行报错如下:
- 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.
复制代码
StackOverFlow上的方案如下(我试了没成功)
stackoverflow
测试代码:
- import multiprocessing
- import parallelTestModule
- def run(name):
- print('%s runing' %name)
- time.sleep(random.randrange(1,5))
- print('%s running end' %name)
-
-
- p1=multiprocessing.Process(target=run,args=('anne',)) #必须加,号
- p2=multiprocessing.Process(target=run,args=('alice',))
- p3=multiprocessing.Process(target=run,args=('biantai',))
- p4=multiprocessing.Process(target=run,args=('haha',))
- p1.start()
- p2.start()
- p3.start()
- p4.start()
- p1.join()
- p2.join()
- p3.join()
- p4.join()
- print('主线程')
复制代码
|
|