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

Question:

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?

Asked By: zer0stimulus

||

Answers:

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.

Answered By: Blender

Shouldn’t the answer be to use ‘close_fds’ flag?

subprocess.Popen(cmd, stdout=None, stderr=None, stdin=None, close_fds=True)
Answered By: PanDe
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.