pycharm无法多进程读取数据导致的报错
问题描述:报错

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.
ForkingPickler(file, protocol).dump(obj)
BrokenPipeError: [Errno 32] Broken pipe
解决方法(三选一):
- 使用cmd / Anaconda Prompt运行python文件
- 将进程数更改为0
def get_dataloader_workers():
return 0
- 将需要运行的内容放入
if __name__=='__main__':(除定义函数/类之外的内容)
在PyCharm中运行程序时遇到了RuntimeError,提示尝试在当前进程初始化之前启动新进程。错误表明可能未使用正确的 fork 模式或者在主模块中遗漏了 `if __name__ == '__main__':` 判断。解决方法包括:通过CMD或Anaconda Prompt运行Python文件,更改数据加载器的工作进程数为0,或者将主要运行内容放入 `if __name__ == '__main__':` 块中。

被折叠的 条评论
为什么被折叠?



