[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.
Read More:
- How to Solve no module fcntl Error in Windows
- How to Solve Python AttributeError: ‘module’ object has no attribute ‘xxx’
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- Python: How to Solve mysqlclient Install Error in Mac
- [Solved] error: unrecognized arguments: –multiprocessing-fork
- How to Solve PyInstaller Package Error: ModuleNotFoundError: No module named ‘xxxx‘
- How to Solve word2vec Module Error: AttributeError & UnicodeDecodeError
- How to Fix keyerror in Python dictionary lookup
- How to Solve Python Xlwt ValueError: More than 4094 XFs (styles)
- How to Solve pyqt5 imports module Error
- How to Solve Python AttributeError: ‘dict’ object has no attribute ‘item’
- Python: How to Solve error While importing windpy
- How to Solve Python ImportError: cannot import name UnrewindableBodyError
- How to Solve Python Libsm. So. 6 error
- How to Solve Python3.9 Install pycrypto Error
- How to Solve Python ShapeFile.writer Error for Beginners
- How to Solve Python Importerror: DLL load failed: unable to find the specified program using tensorflow
- An introduction to sys modules in Python and how packages are imported and used
- How to Solve Python picamera and raspistill error
- Importerror: DLL load failed: unable to find the specified module in Python