i have a simple script that uses multiprocessing to stress the CPU cores.
import multiprocessing
from time import sleep
import math
class StressTestManager:
def stressCpu(self,seconds):
multiprocessing.freeze_support()
processes = []
for _ in range (multiprocessing.cpu_count()):
sleep(0.1)
p = multiprocessing.Process(target =self._generateCpuLoad)
p.start()
processes.append(p)
sleep(seconds)
for process in processes:
process.terminate()
def _generateCpuLoad(self):
while True:
a = math.sqrt(64 * 32)
if __name__ == "__main__":
StressTestManager().stressCpu(10)
this works fine, but when i convert it to an exe file using pyinstaller
pyinstaller --noconfirm --onefile --console "...FolderName/stress_test_manager.py"
and run the file, i get this error, which prints out for each Process i run
Traceback (most recent call last):
File "stress_test_manager.py", line 38, in <module>
ValueError: invalid literal for int() with base 10: 'parent_pid=12004'
[21920] Failed to execute script 'stress_test_manager' due to unhandled exception!
i'm using Python 3.11.5
i've tried to use --onefile and --onefolder, it didn't change anything, i added multiprocessing.freeze_support()
and using a local Process class as mentioned here i still get the same error.
i ended up using py2exe instead, it works just fine with multiprocessing.
it's not exactly a technical solution, but it's a solution to work around this error.