I'm building a small app that tails a log and displays it on the client. However, when I append lines to my log, I lose some data.
Here's the relevant Python handler:
@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()
and here's the JS that receives 'log'
:
socket.on('log', function(data) {
alert("Got some data: ", data['line']);
});
Whenever I append something to the log (for instance echo 'hello, world!' >> /path/to/some_log.log
), I see an alert on the client with the message
"Got some data: "
. However, my server prints "About to emit hello, world!"
.
Why is this happening?