import subprocess proc = subprocess.Popen(['python', 'test.py'], stdout=subprocess.PIPE) while 1: print proc.poll()
#while 1: # print "hello" print "hello"
測試代碼如上,poll函數返回碼:
0 正常結束
1 sleep
2 子進程不存在
-15 kill
None 在運行
poll的返回: 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).
ps:=====================================================================================================
self.proc.poll() == 0 判斷子進程是否正常結束 正確
self.proc.poll() <= 0 會導致進程在一段時間內沒有上報狀態 具體原因??? 有問題
self.proc.poll() is not None判斷進行是否結束