Solution to Code Repetitive Execution in Python Multiprocessing

Question

Calling multiprocessing in Python in a Windows environment When using Process to implement multiple processes, the child process will import the entire parent process script and execute the statement repeatedly.

Solution

Need to join.

if __name__=='__main__'

To determine whether the current script execution carrier is a parent process or a child process. If it is a child process, skip and execute the target function directly. So as to solve the problem.

Stack Overflow Example.

Related articles