I’m trying to run the executable file main.exe
which accepts a parameter and runs the function fun
in other_file.py
. The function fun
uses multiprocessing to perform some computationally intensive tasks. It seems like fun
is run multiple times when main.exe
is called, but the parameter of the function is altered after the first run. Here is a boiled down version of what I’m doing.
main.py
:
import sys
import other_file
if __name__ == '__main__':
> other_file.mp.freeze_support()
> param = sys.argv[1]
> with open(r"check1.txt", 'w') as output:
> > output.write(param)
> output.close()
> other_file.fun(param)
other_file.py
:
import multiprocessing as mp
def fun(param):
> with open(r"check2.txt", 'w') as output:
> > output.write(param)
> output.close()
> # Stuff with multiprocessing below
I converted main.py
to the executable main.exe
using pyinstaller
. When I try to run it via something like the code below check1.txt
contains ‘param_val’ as expected. A few moments later check2.txt
also contains ‘param_val’ as expected, but then yet another few moments later check2.txt
is overwritten and now contains ‘–multiprocessing-fork’. My executable file then throws an error because ‘–multiprocessing-fork’ isn’t an acceptable input for fun
.
import subprocess
subprocess.call([r"main.exe", 'param_val'])