[problem description]
The following code can run normally in Linux, but an error is reported in windows.
import multiprocessing
def fun(): # Child process function
print("child process execution")
p = multiprocessing .Process(target=fun) # Create process object
p.start() # Start the process
p.join() # Recycle process
[solution]
Add code as prompted:
if __name__ == '__main__':
multiprocessing.freeze_support()
Adding only the above code will still report an error (the same error).
The code for creating process objects, starting processes, and recycling processes should also be placed in __ main__
protection
import multiprocessing
def fun(): # Child process function
print("child process execution")
if __name__ =='__main__':
multiprocessing.freeze_support() # Doesn't seem to be added?
p = multiprocessing.Process(target=fun) # Create process object
p.start() # Start the process
p.join() # Recycle process
Done.