2016-04-29 48 views
0

Popen.communicate(timeout=2)可能會提高TimeoutExpired,即使我斷言Popen.poll() is not NonePopen.wait(2)確實不是拋出異常?subprocess:可以溝通()超時,因爲wait()終止?

編輯:docs建議使用下面的代碼片段:

proc = subprocess.Popen(...) 
try: 
    outs, errs = proc.communicate(timeout=15) 
except TimeoutExpired: 
    proc.kill() 
    outs, errs = proc.communicate() 

但這隻會提高ProcessLookupError: [Errno 3] No such process。這是有道理的,因爲我已經通過pollwait終止了這個過程。

回答