0

I need to open a few processes (which are unrelated to Python) to run concurrently to the Python-interpreter ( which launches them, but does not wait for them to finish to continue its own code execution).

Ideally, I will give a callback function for when the process ends.

Example:

def callback(exitcode: int) -> None:
    pass

start_process("g++ file1.cpp", callback=callback)
start_process("gcc file2.c")

If my program terminates before the called programs, I don't care to not get a callback. I have looked at the subprocess module but the functions there wait for the process to end.

user3666197
  • 1
  • 6
  • 50
  • 92
  • You'll have to build the callback functionality yourself using the `asyncio` or `threading` libraries. You're on the right track with using `subprocess` to launch your child processes though. – Woodford Jan 12 '22 at 17:39
  • I am trying to understand the following: How do you envision your program literally terminating yet the compilation process that it started continue to run? Because I am not sure that it can be accomplished without your program hanging around for its started processes to complete. Under Windows I *can* issue a `start cmd /K g++ file1.cpp` command to launch a new command prompt window that *will* continue to run independently after my program terminates but the `start` command will appear to my program to have terminated immediately with a return code of 0. What is your platform? – Booboo Jan 12 '22 at 20:19

0 Answers0