A server utilizing python-socketio socketio.AsyncServer to handle very simple IO operations. Everything works:
- Client sends message to check status
- Server returns status
Problem
asyncio.run(sio.emit('status', repr(cb)))
, does not seem to reach the client immediately, but in a randomly delayed fashion (varying between 0.5 to 5 seconds). The strange thing is a new asyncio.run(...)
would cause the previous "task" to execute. In this case, stacking multiple asyncio.run(sio.emit(...))
would cause all the tasks to get executed, except for the very last one.
Below is a code snippet on the server side:
def callback_status(cb):
print("Returning status: ", repr(cb)) #this gets executed just fine but the following is randomly delayed
asyncio.run(sio.emit('status', repr(cb)))
@sio.on('message')
async def get_status(sid, message):
get_some_status(callback_status) #not an async function
sio = socketio.AsyncServer()
app = web.Application()
sio.attach(app)
if __name__ == '__main__':
web.run_app(app, host='0.0.0.0')
I have verified that this is not something concerning the client side as I have used another method to setup a server and the 'status' messages, once emitted, get received on the client side immediately. The reason why I am using socketio.AsyncServer is such that the client may utilize a WebSocket connection (as opposed to http connection) for persistent, lower-overhead bi-directional communication.