我尝试运行一个非常简单的Dask程序,如下所示:
# myfile.py
from dask.distributed import Client
client = Client()
但是当我运行这个程序时,我得到了这个奇怪的错误
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.
发布于 2020-02-14 19:55:18
在调用Client()
或LocalCluster()
时,您在程序中启动了一些新进程。当模块或脚本像这样启动进程时,Python不喜欢这样。
要解决此问题,请将代码包含在if __name__ == "__main__":
块中,如下所示:
# client = Client()
if __name__ == '__main__':
client = Client()
...
或者,您可以选择安全地使用线程而不是进程。
client = Client(processes=False)
此外,如果在IPython或Jupyter等交互式会话中运行,则不会出现此问题
https://stackoverflow.com/questions/60232708
复制