1.问题

  File "F:\pythonproject\gpt2\lib\site-packages\multiprocess\popen_spawn_win32.py", line 45, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "F:\pythonproject\gpt2\lib\site-packages\multiprocess\spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "F:\pythonproject\gpt2\lib\site-packages\multiprocess\spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
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

2.解决

定义一个函数,将运行代码放进函数中

def test():
    #这里是之前运行代码

再加入main函数调用即可解决。

if __name__ == '__main__':
    test()

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐