关于An attempt has been made to start a new process before the current process has finish的解决办法

在按照官方demo做cifar识别的时候,在pycharm上会出现一长串的红色字母,转去jupyter 发现并没有错,就很好奇。

对于图像识别分类的时候,在dataloader的时候有时会有num_workers的参数,这表示线程数,num_workers=0表示单线程,num_workers = 2则表示多线程。当是多线程的时候直接运行程序也许会出现这种错误。

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.
解决办法

1、 可以将多线程改为单线程。
2、 可以添加 if name == ‘main 进行主程序调用。

你可能感兴趣的:(Python)