先举个例子
import multiprocessing
def test():
while True:
pass
p1 = multiprocessing.Process(target=text)
p1.start
test()
代码本身没有逻辑上的毛病,但是在linux系统环境下能够运行却在windows系统环境下运行不了
下面放出在Windows系统环境下运行后所报出的错误:
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":
这一段,也就是说只要在创建进程对象之前记得打上这段代码就能解决问题