首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Dask失败并出现freeze_support错误

Dask失败并出现freeze_support错误
EN

Stack Overflow用户
提问于 2020-02-15 03:55:18
回答 1查看 1.3K关注 0票数 5

我尝试运行一个非常简单的Dask程序,如下所示:

代码语言:javascript
代码运行次数:0
运行
复制
# myfile.py
from dask.distributed import Client

client = Client()

但是当我运行这个程序时,我得到了这个奇怪的错误

代码语言:javascript
代码运行次数:0
运行
复制
    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.
EN

回答 1

Stack Overflow用户

发布于 2020-02-15 03:55:18

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

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

代码语言:javascript
代码运行次数:0
运行
复制
# client = Client()

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

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

代码语言:javascript
代码运行次数:0
运行
复制
client = Client(processes=False)

此外,如果在IPython或Jupyter等交互式会话中运行,则不会出现此问题

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60232708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档