python socket-io emit() doesn’t send time until after execution

  flask, javascript, python, python-socketio, websocket

Using the python socketio package, I created a timer that starts when a client connects to my server.

Server-side code:

import socketio

sio = socketio.Server()
app = socketio.WSGIApp(sio, static_files={
    '/': './public/'

def connect(sid, environ):
    count = 10
    while count > 0:
        sio.emit('timer_count', count)
        count -= 1

HTML code for reference (index.html):

<!doctype html>
        <h1>Timer Build</h1>
        <p1 id="counter"></p1>
        <script src=""></script>
        <script src="/index.js"></script>

Client-side JS code (index.js):

const sio = io();

sio.on('timer_count', function(count) {
    var s = document.getElementById("counter");
    s.innerHTML = count;

However, the behavior I am getting is that the data isn’t emitted to the client until it appears the server side code is finished executing (i.e. the whole count is printed all at once). How can I get this to behave in a true timer fashion where the console.log() function prints the data (count) every second?

Source: Python Questions