__init __()在python子进程中得到了一个意外的关键字参数'timeout'

Cha*_*hna 3 python subprocess

我正在尝试运行以下使用pythos'subprocess'模块的代码.

subprocess.call(cli_args, stdout=client_log, stderr=client_log, timeout=10)
Run Code Online (Sandbox Code Playgroud)

我正在使用超时争论,如果子进程卡在中间,通过杀死它,这里提到要跳过此行.但是当我运行它时,我得到了以下错误.

Traceback (most recent call last):
  File "test.py", line 152, in <module>
    ret = runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, protocol, transport, 9090, 0, 0)
  File "test.py", line 102, in runServiceTest
    ret = subprocess.call(cli_args, stdout=client_log, stderr=client_log, timeout=10)
  File "/usr/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
TypeError: __init__() got an unexpected keyword argument 'timeout'
Run Code Online (Sandbox Code Playgroud)

这是什么原因?我怎么解决这个问题?我的完整代码可以在这里找到.

tim*_*geb 6

根据您的print陈述判断,您使用的是Python2.x,其中subprocess.call没有timeout参数:

subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
Run Code Online (Sandbox Code Playgroud)

https://docs.python.org/2/library/subprocess.html