window python 主函数 写 if __name__ == "__main__": 可以避免多进程等错误(训练yolov8时出现的)

训练yolov8时出现

类似以下错误:

  

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 是用 fork,windows 是用spawn,spawn要加 if __name__ == "__main__": 区分主进程。

参考:Python 中的多线程和多进程(上) - 知乎 (zhihu.com)

posted on 2023-01-15 14:47  WenJXUST  阅读(747)  评论(0)    收藏  举报