Reputation: 23676
I'm currently using subprocess.call() to invoke another program, but it blocks the executing thread until that program finishes. Is there a way to simply launch that program without waiting for return?
Upvotes: 50
Views: 46871
Reputation: 298552
Use subprocess.Popen
instead of subprocess.call
:
process = subprocess.Popen(['foo', '-b', 'bar'])
subprocess.call
is a wrapper around subprocess.Popen
that calls communicate
to wait for the process to terminate. See also What is the difference between subprocess.popen and subprocess.run.
Upvotes: 78
Reputation: 974
Shouldn't the answer be to use 'close_fds' flag?
subprocess.Popen(cmd, stdout=None, stderr=None, stdin=None, close_fds=True)
Upvotes: 1