Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python subprocess.call阻塞_Python - Fatal编程技术网

Python subprocess.call阻塞

Python subprocess.call阻塞,python,Python,我正在尝试使用subprocess.call在Python中运行外部应用程序。据我所知,除非调用Popen.wait,否则subprocess.call不应该阻塞,但对我来说,在外部应用程序退出之前,subprocess.call一直处于阻塞状态。如何修复此问题?您看错了文档。据他们说: subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False) 运行args描述的命令。等待命令完成,然后返回retur

我正在尝试使用subprocess.call在Python中运行外部应用程序。据我所知,除非调用Popen.wait,否则subprocess.call不应该阻塞,但对我来说,在外部应用程序退出之前,subprocess.call一直处于阻塞状态。如何修复此问题?

您看错了文档。据他们说:

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

运行args描述的命令。等待命令完成,然后返回returncode属性。

子流程中的代码实际上非常简单且可读。只要看到或版本(视情况而定),您就可以知道它在做什么

例如,
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

无需调用
等待
即可执行相同的操作。创建一个
Popen
,不要调用
wait
,这正是您想要的。

哦,好的。我如何复制使用选项P_NOWAIT调用os.spawnl的功能?@dpitch40-。很有帮助,但很谦虚。