・ 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
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) )
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