Project scenario:
When running python code under the windows platform, an error occurs:
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.
Cause Analysis:
① This is because multiple child processes can be used to load data in the Linux system, but not in the Windows system.
②This error is due to the fact that on the Windows platform, when using multiple processes, conditional judgments need to be added to the code if __name__ == '__main__':
to ensure that the main module has completed the initialization phase before starting the sub-process.
solution:
1. If used in the code num_worker
, the number of processes needs to be set to a single process in the Windows system, so we need to change the parameters in this part of the data processing statement num_workers=0
to solve the error.
2. My code is the second case. To solve this problem, you can wrap your code in if __name__ == '__main__':
conditional judgment and it will be solved.