我正在尝试使用子进程从日志文件中提取行。这里的意图是在某些程序正在执行时提取日志,并等待一段时间将所有日志复制到另一个文件。python为什么这个子进程命令不能按预期工作
#!/bin/python
import threading
import time, subprocess
class GetLogs(threading.Thread):
'''
Get the developer logs
'''
def __init__(self):
'''
init
'''
self.stop = False
threading.Thread.__init__(self)
print "Initialised thread"
def run(self):
'''
Collect the logs from devlog
'''
command = "tail -f /var/log/developer_log | tee /tmp/log_collected"
response = subprocess.check_output(command.split(), shell=True)
print "Subprocess called"+str(response)
while (self.stop is False):
time.sleep(1)
print "Continuing"
continue
print "Finished the log file"
gl = GetLogs()
gl.start()
##Do some activity here
print "Sleeping for 10 sec"
time.sleep(10)
gl.strop = True
print "Done"
这不起作用 - 程序卡住了。
你不能这样等待子进程 – YOU