为什么subprocess.Popen.poll=0,但是pipe里面还有没读完的数据
答案:2 悬赏:70 手机版
解决时间 2021-12-19 01:44
- 提问者网友:我一贱你就笑
- 2021-12-18 21:45
为什么subprocess.Popen.poll=0,但是pipe里面还有没读完的数据
最佳答案
- 五星知识达人网友:不想翻身的咸鱼
- 2021-12-18 23:22
if subprocess.Popen.poll(pp) !=None:
break
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).
break
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).
全部回答
- 1楼网友:忘川信使
- 2021-12-19 00:32
可能标题写的有点不清楚,具体情况如下:
写一个程序,能获得程序输出,并且在程序执行完毕之后,能获知。程序如下
import subprocess
pp = subprocess.popen('ping -c4 www.google.cn', shell=true, stdout=subprocess.pipe, stderr=subprocess.stdout)
while 1:
line = pp.stdout.readline()
print('out-->'+line+'<')
if subprocess.popen.poll(pp)==0:
break
print('done')
实际执行的效果有2种情况
第一种
out-->ping www.google.cn (203.208.45.212) 56(84) bytes of data.<
out-->64 bytes from 203.208.45.212: icmp_seq=1 ttl=55 time=4.03 ms<
out-->64 bytes from 203.208.45.212: icmp_seq=2 ttl=55 time=3.18 ms<
out-->64 bytes from 203.208.45.212: icmp_seq=3 ttl=55 time=3.90 ms<
out-->64 bytes from 203.208.45.212: icmp_seq=4 ttl=55 time=4.47 ms<
done
---------------------------
第二种
out-->ping www.google.cn (203.208.46.212) 56(84) bytes of data.<
out-->64 bytes from 203.208.46.212: icmp_seq=1 ttl=54 time=26.3 ms<
out-->64 bytes from 203.208.46.212: icmp_seq=2 ttl=54 time=3.22 ms<
out-->64 bytes from 203.208.46.212: icmp_seq=3 ttl=54 time=6.95 ms<
out-->64 bytes from 203.208.46.212: icmp_seq=4 ttl=54 time=4.59 ms<
out--><
out-->--- www.google.cn ping statistics ---<
out-->4 packets transmitted, 4 received, 0% packet loss, time 3009ms<
out-->rtt min/avg/max/mdev = 3.225/10.282/26.363/9.380 ms<
out--><
out--><
out--><
out--><
done
第一种执行结果占多数,第二种执行结果,有时候会出现。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯