Creating an exe file with Python PyInstaller: PC freezes in parallel processing

PC freezes when executing Python parallel processing with exe

Execution environment

・ Windodws10 ・ Python 3.8.3 ・ PyInstaller 3.6

When parallel processing that does not occur from the console is made into an exe file with PyInstaller and clicked, a lot of exe processes start up and the PC freezes. Despair

Conclusion

Requires freeze_support ()

Python parallel processing sample that freezes PC when executed with exe file

Parallel processing sample



from multiprocessing import Pool 

#####In this case, a function that returns the square of the argument###
def nijou(x):
    print( x*x )
 
######Let's calculate in parallel#########
if __name__ == "__main__":
    p = Pool(4)
    p.map( nijou, range(10) )

I needed to write freeze_support ()

This function should be called immediately after if name =='main' in the main module If there is no freeze_support () line, RuntimeError when trying to execute a frozen executable Will occur Calling freeze_support () has no effect on operating systems other than Windows. In addition, freeze_support () has no effect if the module is run by a regular Windows Python interpreter (unless the program is frozen).

Reference here-multiprocessing process-based parallel processing

It does not freeze even if it is executed by exe



from multiprocessing import Pool,freeze_support
#freeze_Add support

#####In this case, a function that returns the square of the argument###
def nijou(x):
    print( x*x )
 
######Let's calculate in parallel#########
if __name__ == "__main__":
    freeze_support() #Added
    p = Pool(4)
    p.map( nijou, range(10) )

Recommended Posts

Creating an exe file with Python PyInstaller: PC freezes in parallel processing
[Python Kivy] How to create an exe file with pyinstaller
Create an exe file that works in a Windows environment without Python with PyInstaller
File processing in Python
Parallel processing with no deep meaning in Python
An introduction to Python distributed parallel processing with Ray
Creating an egg with python
Create an Excel file with Python3
Read files in parallel with Python
Create an executable file (EXE) by PyInstaller in a hybrid environment (Nimporter) of Python + Nim
Make Scrapy an exe with Pyinstaller
When I run the exe file with pyinstaller, my PC crashes.
Python script written in PyTorch is converted to exe with PyInstaller
Creating a simple PowerPoint file with Python
Exclusive control with lock file in Python
Automatic update method with python Pyinstaller exe
How to convert Python to an exe file
Note when creating an environment with python
Quickly create an excel file with Python #python
Easy image processing in Python with Pillow
Receive a list of the results of parallel processing in Python with starmap
How to do multi-core parallel processing with python
Read table data in PDF file with Python
[Automation] Convert Python code into an exe file
Python file processing
Develop Windows apps with Python 3 + Tkinter (exe file)
Create an image with characters in python (Japanese)
GUI (WxPython) executable file (pyInstaller) [Windows] in Python3
Send an email with Excel attached in Python
Make each PowerPoint page an image file in Python
Building an environment for natural language processing with Python
PyInstaller memorandum Convert Python [.py] to [.exe] with 2 lines
Run a Python file with relative import in PyCharm
File operations in Python
Multithreaded processing in python
Parallel download in Python
Text processing in Python
Queue processing in Python
File operations in Python
Image processing with Python
Parallel processing with multiprocessing
Try creating a Deep Zoom file format .DZI in Python
Basic authentication with an encrypted password (.htpasswd) in bottle with python
Select file in dialog with python → Display file name in message box
How to read an Excel file (.xlsx) with Pandas [Python]
Image processing with Python (Part 2)
100 Language Processing with Python Knock 2015
UTF8 text processing in python
Quicksort an array in Python 3
Parallel processing with local functions
Scraping with selenium in Python
"Apple processing" with OpenCV3 + Python3
Working with LibreOffice in Python
Download the file in Python
Debugging with pdb in Python
Run Python unittests in parallel
Draw netCDF file with python
Acoustic signal processing with Python
Working with sounds in Python
Parallel processing with Parallel of scikit-learn
Image processing with Python (Part 1)