我使用multiprocessing.pool并默认使用macOS,但我还需要在Windows上试用它。它在macOS上运行完美,但是当我尝试在Windows上运行它只显示无限的错误消息......我甚至无法杀死该程序。
我已经看到Windows上的启动方法是' spawn'并且在macOS上是' fork'默认情况下。这是问题吗?如果是,我该如何解决?
以下代码的一部分:
pool = Pool(processes = numprocs)
# evaluate fitness of particles in swarm
swarm = pool.map_async(partial(proxy, costf = costFunc, i=i),Swarm)
pool.close()
pool.join()
pool.terminate()
Swarm = swarm.get()
EDIT1:
我能够收到错误消息,我的错误。
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.