【报错记录】----RuntimeError:An attempt........ if __name__ == ‘__main__‘: freeze_support()

概述

今天在跑一个代码时,报了

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

如下图所示:
在这里插入图片描述

分析

刚开始查资料说是在代码开始时,添加下面代码:

import os
os.environ["CUDA_VISIBLE_DEVICES"]='0'

但是并未解决问题。


又查到一篇博客,说是多线程的问题。

解决办法

去掉num_workers参数
我的代码中,有这个参数:
在这里插入图片描述
将其屏蔽掉之后,再次运行代码就不再报错了。

参考资料

[1] https://blog.csdn.net/u013700358/article/details/82753019

猜你喜欢

转载自blog.csdn.net/hshudoudou/article/details/127339724