架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

搜索
查看: 1231|回复: 0

[已解决] The "freeze_support()" line can be omitted if the program is not...

[复制链接]
发表于 2024-11-14 13:12:46 | 显示全部楼层 |阅读模式
PyTorch错误:The “freeze_support()” line can be omitted if the program is not going to be frozen to produce an executable.

错误代码如下:

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.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.

解决方案

将你要运行的代码块放到main函数中运行即可,例如:

区别

不加 if __name__ == '__main__'::模块中的代码(包括函数调用)在导入时也会被执行。
加 if __name__ == '__main__'::模块中的代码(包括函数调用)只有在模块作为主程序运行时才会执行,而在导入时不执行。

这种模式有助于提高代码的可重用性和模块化,避免在导入模块时意外执行某些代码。




上一篇:Windows 下飞桨 PaddlePaddle 安装教程
下一篇:英伟达 Nvidia 相关软件下载
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|手机版|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2025-6-15 20:42

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表