解决RuntimeError: An attempt has been made to start a new process before...办法

参考:https://zhuanlan.zhihu.com/p/553407062
跑测试时出现的问题:

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.

报错
原因:

这是因为在linux系统中可以使用多个子进程加载数据,而在windows系统中不能。在windows系统中需要将进程数设置为单进程,所以我们需要将数据处理语句这部分的参数num_workers=2改为num_workers=0即可解决错误。

解决方法:
将该文件下的num_workers改为0,原始参数为16.
解决RuntimeError: An attempt has been made to start a new process before...办法_第1张图片

你可能感兴趣的:(经验分享)