from subprocess import *
import datetime,time
import threading
import os,sys

def runcmd():
    cmd = ["ping","-t","www.baidu.com"]
    r=Popen(cmd,stdin=PIPE,stdout=PIPE,stderr=PIPE)
    for i in iter(r.stdout.readline,b""):
        print(i.decode("gbk").strip())

child = threading.Thread(target=runcmd)
child.daemon=True
child.start()
num = 0
timeout = 30
while True:
    time.sleep(1)
    num += 1
    print("Now num ",num)
    if num == timeout:
        os._exit(0)

 

Now num  28
来自 112.80.248.75 的回复: 字节=32 时间=20ms TTL=55
Now num  29
来自 112.80.248.75 的回复: 字节=32 时间=10ms TTL=55
Now num  30

 

相关文章:

  • 2021-12-06
  • 2021-11-19
  • 2023-02-21
  • 2021-11-28
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-11-28
猜你喜欢
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
  • 2021-12-01
  • 2021-09-26
  • 2021-05-30
  • 2022-12-23
相关资源
相似解决方案