Python 执行tail文件并操作
def log_search(self, logfile, search_content, timeout=10): import time import subprocess import select import signal import os f = subprocess.Popen([‘tail‘, ‘-F‘, logfile], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = select.poll() p.register(f.stdout) try: while timeout>0: if p.poll(500): # millisecond timeout while True: line = f.stdout.readline() if line: if search_content in line: return True else: # no content read out break time.sleep(1) timeout -= 1 else: return False finally: print(‘unregister‘) p.unregister(f.stdout) print(‘kill pid‘) os.kill(f.pid, signal.SIGKILL)
相关推荐
dflyzx 2020-09-17
higheels 2020-07-20
Ericbig 2020-07-19
yinyang00 2020-05-15
lijiuchangxin 2020-05-14
yogoma 2020-05-09
jacktangj 2020-04-19
Yyqingmofeige 2020-03-26
idning 2020-02-14
宿舍 2020-01-31
luenxin 2020-01-22
水痕 2020-01-18
chouliqingke 2020-01-08
secondid 2019-12-18
XCodeRush 2019-12-17
ryuhfxz 2019-11-20
qonsnow 2014-03-07
coulder 2019-11-17