[英]Python subprocess.call blocking
我试图用subprocess.call在Python中运行外部应用程序。 从我读过的内容来看,除非你调用Popen.wait,否则subprocess.call不应该阻塞,但对我来说它是阻塞的,直到外部应用程序退出。 我该如何解决?
你正在阅读错误的文档。 根据他们:
subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
运行args描述的命令。 等待命令完成,然后返回returncode属性。
subprocess
的代码实际上非常简单易读。 只需看看3.3或2.7版本(视情况而定),您就可以知道它在做什么。
例如, call
如下所示:
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
你可以在不叫wait
的情况下做同样的事情。 创建一个Popen
,不要wait
它,这正是你想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.