Python Subprocess Lock

I am trying to run an external application in Python using subprocess.call. From what I read, subprocess.call should not be blocked unless you call Popen.wait, but for me it is blocked until the external application exits. How to fix it?

+7
source share
2 answers

The code in subprocess is actually quite simple and readable. Just review the 3.3 or 2.7 version (as needed) and you can tell what it does.

For example, call looks like this:

 def call(*popenargs, timeout=None, **kwargs): """Run command with arguments. Wait for command to complete or timeout, then return the returncode attribute. The arguments are the same as for the Popen constructor. Example: retcode = call(["ls", "-l"]) """ with Popen(*popenargs, **kwargs) as p: try: return p.wait(timeout=timeout) except: p.kill() p.wait() raise 

You can do the same without calling wait . Create a Popen , don't call wait on it, and that is exactly what you want.

-one
source

You are not reading documents correctly. According to them:

 subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False) 

Run the command described by args. Wait for the command to complete, and then return the returncode attribute.

+5
source

All Articles