zer0stimulus
zer0stimulus

Reputation: 23676

Can subprocess.call be invoked without waiting for process to finish?

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

Answers (2)

Blender
Blender

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

PanDe
PanDe

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

Related Questions