Concurrent.futures works well in command line, not when compiled with pyinstaller

Viewed 222

I have a python script which takes custom command line arguments and calls concurrent.futures.ProcessPoolExecutor

This calls multiprocessing.resource_tracker which has the following code

cmd = 'from multiprocessing.resource_tracker import main;main(%d)'
r, w = os.pipe()
try:
    fds_to_pass.append(r)
    # process will out live us, so no need to wait on pid
    exe = spawn.get_executable()
    args = [exe] + util._args_from_interpreter_flags()
    args += ['-c', cmd % r]

works well in command line

Now when compiled with pyinstaller, when this code gets executed, the file where I am taking input arguments is getting called and I getting the following error

Argument Parsing Error - invalid choice: 'from multiprocessing.resource_tracker import main;main(11)'

I have used freeze_support but no use. How to avoid this error? Is there any way in which we can accept those arguments?

Python Version: 3.8, Pyinstaller version: 3.6 OS: Darwin

1 Answers

The problem is probably that spawn.get_executable() is your "compiled" program when started from PyInstaller, where it is pointing on the installed python version otherwise.

The argument parsing of your program refuses the complex arguments that you're passing.

You should distribute your program without pyinstaller, but with a (portable) python installation like Anaconda.

The alternative would be to add an option in your parser to accept a -c switch which takes an argument.

When this switch is passed, just call exec on what is passed to simulate -c python switch.

Related