Guest User
September 19, 2024
還可以吧,還行,衞生再好一點就行了,
服務:一般
環境:還好
衞生:也還行,湊合的過去
設施:不咋全乎
# -*- coding: utf-8 -*-
import shlex
import os
import signal
import time
import threading
from subprocess import Popen, PIPE
def run_command(command):
process = Popen(shlex.split(command), stdout=PIPE)
st = time.time()
while True:
output = process.stdout.readline().r*****().decode('utf-8')
if output == '' and process.poll() is not None:
break
if output:
print(output.*****())
if time.time() - st > 3:
os.kill(process.pid, signal.CTRL_C_EVENT)
break
rc = process.poll()
return rc
if __name__ == "__main__":
t = threading.Thread(target=run_command, args=("ping baidu.com",))
t.start()
Translate