我正在嘗試使用子進程從日誌文件中提取行。這裏的意圖是在某些程序正在執行時提取日誌,並等待一段時間將所有日誌複製到另一個文件。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