我有下面的Python代码:
strRunOutput = subprocess.run([strFastbootExecutable, "-s", dsn.upper(), "reboot"], timeout=5, stderr=subprocess.PIPE).stderr.decode('utf-8').upper()
基本上就是这样:
fastboot -s G070GV1871970FCW reboot
这是它的输出
< waiting for G070GV1871970FCW >
...这是挂起。为什么fastboot命令挂起,我不知道,但更困扰我的是,www.example.com命令没有超时后5秒,因为我告诉它,并导致我的程序挂起。任何想法是怎么回事?subprocess.run command isn't timing out after 5 seconds as I told it to and is causing my program to hang. Any ideas what's going on?
谢谢!
2条答案
按热度按时间umuewwlo1#
这是一个已知问题-Python bug跟踪器上有两个与此相关的票证。
不是因为你接了个管子就超时了。
Issue31935: subprocess.run() timeout not working with grandchildren and stdout=PIPE
Issue30154: subprocess.run with stderr connected to a pipe won't timeout when killing a never-ending shell commanad (sic)
qmb5sa222#
问题是因为管道。然而,以下方法即使有管道也对我有效:
来源:https://github.com/python/cpython/issues/81605