第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用Python子進程通訊方法時如何獲取退出代碼?

使用Python子進程通訊方法時如何獲取退出代碼?

人到中年有點甜 2019-12-17 14:52:07
使用Python的subprocess模塊和communicate()方法時,如何檢索退出代碼?相關(guān)代碼:import subprocess as spdata = sp.Popen(openRTSP + opts.split(), stdout=sp.PIPE).communicate()[0]我應(yīng)該以其他方式這樣做嗎?
查看完整描述

3 回答

?
慕蓋茨4494581

TA貢獻1850條經(jīng)驗 獲得超11個贊

Popen.communicate完成后將設(shè)置returncode屬性(*)。這是相關(guān)的文檔部分:


Popen.returncode 

  The child return code, 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).

所以您可以做(我沒有測試過,但是應(yīng)該可以):


import subprocess as sp

child = sp.Popen(openRTSP + opts.split(), stdout=sp.PIPE)

streamdata = child.communicate()[0]

rc = child.returncode

(*)發(fā)生這種情況的原因是它的實現(xiàn)方式:設(shè)置線程以讀取子流后,它僅調(diào)用wait。


查看完整回答
反對 回復(fù) 2019-12-17
?
慕標(biāo)琳琳

TA貢獻1830條經(jīng)驗 獲得超9個贊

您首先應(yīng)確保該過程已完成運行,并且已使用該.wait方法讀取了返回代碼。這將返回代碼。如果您以后想要訪問它,則將其存儲.returncodePopen對象中。


查看完整回答
反對 回復(fù) 2019-12-17
?
小唯快跑啊

TA貢獻1863條經(jīng)驗 獲得超2個贊

.poll() 將更新返回碼。


嘗試


child = sp.Popen(openRTSP + opts.split(), stdout=sp.PIPE)

returnCode = child.poll()

另外,在.poll()調(diào)用之后,該對象中的返回碼可用child.returncode。


查看完整回答
反對 回復(fù) 2019-12-17
  • 3 回答
  • 0 關(guān)注
  • 665 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號