Python subprocess.call blocking
I am trying to run an external application in Python with subprocess.call. From what I've read it subprocess.call isn't supposed to block unless you call Popen.wait, but for me it is blocking until the external application exits. How do I fix this?
The code in subprocess
is actually pretty simple and readable. Just see the 3.3 or 2.7 version (as appropriate) and you can tell what it's doing.
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 thing without calling wait
. Create a Popen
, don't call wait
on it, and that's exactly what you want.
You're reading the docs wrong. According to them:
subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
Run the command described by args. Wait for command to complete, then return the returncode attribute.
链接地址: http://www.djcxy.com/p/68416.html上一篇: 映射关键是自定义对象的位置?