'Python multiprocess does not multiprocess after being built into an exe
I'm trying to build a python script into an exe file which runs 8 variables for one file in parallel using the multiprocessing pool class. I have included a timer to check the run time of the script and one file should finish in around 70 seconds if the multiprocess is working (which it does when running as .py). However, after I have built the script into and exe using pyinstaller 5.0.1, the run time of the program became around 160 seconds, and this is the duration the program needs when running NOT in parallel processing. (and also if I open task manager I can see the CPU usage is much less than running in .py)
I have already included freeze_support() right after if name == 'main':
The code for the multiprocessing is as below
for i in range(len(path1kmfilelist)):
start=time.perf_counter()
PATH1km=path1kmfolder+'\\'+path1kmfilelist[i]
PATHcar=pathcarfolder+'\\'+pathcarfilelist[i]
p=Pool(8)
pollutants=[list of 8 variables]
data=[8 tuples]
print(f'Now modifying {PATH1km}')
p.starmap(projection, data)
p.close()
finish=time.perf_counter()
print(f'Finished {PATH1km} in {round(finish-start)} seconds.')
For building the exe I used the following
pyinstaller --console --hiddenimport cftime myscript.py
Is there a way to know if the exe is actually multiprocessing? And if no, would like to know how to properly build the exe. Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
