An attempt has been made to start a new process before the current process has finished its

对vgg进行剪枝的时候,在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、 可以将多线程改为单线程,即在代码中令num_workers=0

2、 可以添加 if name == ‘main’ 进行主程序调用。

你可能感兴趣的:(程序调试,python)