达斯克失败,并带有Frozen_support错误

时间:2020-02-14 19:55:17

标签: python python-multiprocessing dask

我尝试运行一个非常简单的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.

1 个答案:

答案 0 :(得分:3)

调用Client()LocalCluster()时,您正在程序中启动一些新进程。当模块或脚本启动这样的过程时,Python不喜欢它。

要解决此问题,请将您的代码包含在if __name__ == "__main__":块中,如下所示:

# client = Client()

if __name__ == '__main__':
    client = Client()
    ...

或者,您可以选择使用线程而不是安全地处理进程。

client = Client(processes=False)

此外,如果您在IPython或Jupyter之类的交互式会话中运行,也不会发生此问题

相关问题