is there a way to call an external program inside python and don't wait for its execution to finish?
I tried this, but no luck:
os.system("external_program &")
Normally, if I call external_program &
inside a bash shell it executes as a background process.
How can I do it inside python? For, my special case, creating another thread does not work. After main python scrip is done, the external program should continue its execution.
Yes, use the subprocess
module. For example:
p = subprocess.Popen(['external_program', 'arg1', 'arg2'])
# Process is now running in the background, do other stuff...
...
# Check if process has completed
if p.poll() is not None:
...
...
# Wait for process to complete
p.wait()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With