Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/127.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:将子流程模块从v3.3导入到v2.7.4_Python_Python 2.7_Python 3.x_Future - Fatal编程技术网

Python:将子流程模块从v3.3导入到v2.7.4

Python:将子流程模块从v3.3导入到v2.7.4,python,python-2.7,python-3.x,future,Python,Python 2.7,Python 3.x,Future,我想将子流程模块从py v3.3导入v2.7,以便能够使用超时功能 读了几篇文章后,我试着这样做 from __future__ import subprocess 但它说: SyntaxError: future feature subprocess is not defined 然后我发现future没有任何功能子流程 因此,我应该在哪里以及如何从v3.3导入子流程?我认为后端口是个好主意。下面是子流程调用的比较。注意,在Python2中,在*popenargs之后使用命名参数timeo

我想将
子流程
模块从py v3.3导入v2.7,以便能够使用
超时
功能

读了几篇文章后,我试着这样做

from __future__ import subprocess
但它说:

SyntaxError: future feature subprocess is not defined
然后我发现future没有任何功能
子流程


因此,我应该在哪里以及如何从v3.3导入
子流程?

我认为后端口是个好主意。下面是
子流程调用的比较。注意,在Python2中,在
*popenargs
之后使用命名参数
timeout
是一个语法错误,因此backport有一个解决方法。其他函数的超时参数的处理方式与此类似。如果您对超时的实际实现方式感兴趣,您应该查看
Popen的
wait
方法

Python2.7子流程 Python3.3子流程 Python2.7子流程32后端口
有一个后端口:2.7版本有什么问题?(通常,您无法在旧版本中使用新版本的功能。如果可以,新版本将不存在;它将与旧版本相同。
\uuuuuu future\uuuuuuu
是为了逐步引入向后不兼容的更改。)不幸的是,后移植在Windows中不起作用(出于各种原因)。使用诸如MinGW之类的工具进行交叉编译可能会使使用它成为可能,但我仍然不知所措,因为它修复了大量的bug,但是关于subprocess32的官方URL声明它只为符合POSIX的系统提供支持。
def call(*popenargs, **kwargs):
    """Run command with arguments.  Wait for command to complete, then
    return the returncode attribute.

    The arguments are the same as for the Popen constructor.  Example:

    retcode = call(["ls", "-l"])
    """
    return Popen(*popenargs, **kwargs).wait()
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
def call(*popenargs, **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"])
    """
    timeout = kwargs.pop('timeout', None)
    p = Popen(*popenargs, **kwargs)
    try:
        return p.wait(timeout=timeout)
    except TimeoutExpired:
        p.kill()
        p.wait()
        raise