这个测试代码
import subprocess
out=subprocess.run(["sleep","10"], timeout=1)
在 Python 3.5.3 下生成以下输出:
Traceback (most recent call last):
File "/usr/lib/python3.5/subprocess.py", line 385, in run
stdout, stderr = process.communicate(input, timeout=timeout)
File "/usr/lib/python3.5/subprocess.py", line 801, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "/usr/lib/python3.5/subprocess.py", line 1476, in _communicate
self.wait(timeout=self._remaining_time(endtime))
File "/usr/lib/python3.5/subprocess.py", line 1385, in wait
raise TimeoutExpired(self.args, timeout)
subprocess.TimeoutExpired: Command '['sleep', '10']' timed out after 0.9999505979940295 seconds
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/subprocess.py", line 390, in run
stderr=stderr)
subprocess.TimeoutExpired: Command '['sleep', '10']' timed out after 1 seconds
这两个异常消息中的第一个是不恰当且令人困惑的。它包含 Python API 的普通用户不想看到的内部结构。它表明 subprocess.py 中存在问题,尽管预期 subprocess 的常规行为会默默地处理应用程序程序员施加的超时。
有没有办法获得更清晰的异常消息?
我应该在 Python 问题跟踪器上提出这个投诉吗?