0
我正在構建一個小應用程序,它會將日誌尾部顯示在客戶端上。但是,當我在日誌中添加行時,會丟失一些數據。爲什麼socket.io中的數據丟失?
下面是相關的Python處理器:
@socketio.on('Request logs')
def handle_request_logs():
logfile = '/path/to/some_log.log'
# gets last 25 lines from logfile
last_n_lines = tailer.tail(open(logfile), 25)
# sends the initial 25 lines
emit('Initial send', { 'lines' : last_n_lines })
# emits lines that were appended to logfile
@copy_current_request_context
def tail(logfile):
for line in tailer.follow(open(logfile)):
print("About to emit {0}".format(line))
emit('log', { 'line' : line })
# emit added lines as they come
t = threading.Thread(target=tail, args=(logfile,))
t.start()
和這裏的接收'log'
的JS:
socket.on('log', function(data) {
alert("Got some data: ", data['line']);
});
每當我一些東西附加到日誌(例如echo 'hello, world!' >> /path/to/some_log.log
),我就看到一個警告該客戶端的消息爲 "Got some data: "
。但是,我的服務器打印。
這是怎麼發生的?
啊...我恨我自己。 – erip