Popen.communicate完成后将设置
returnpre属性(*)。这是相关的文档部分:
Popen.returnpre The child return pre, set by poll() and wait() (and indirectly by communicate()). A None value indicates that the process hasn’t terminated yet. A negative value -N indicates that the child was terminated by signal N (Unix only).
所以您可以做(我没有测试过,但是应该可以):
import subprocess as spchild = sp.Popen(openRTSP + opts.split(), stdout=sp.PIPE)streamdata = child.communicate()[0]rc = child.returnpre
(*)发生这种情况的原因是它的实现方式:设置线程以读取子流后,它仅调用
wait。



