0

How to push tasks regularly? i try it like this but client tips packet queue is empty, aborting

sio = socketio.Server(cors_allowed_origins="*")
app = socketio.WSGIApp(sio, static_files={'/': {'content_type': 'text/html', 'filename': 'index.html'}})

def check_wait_reply():
    sio.emit('message', 123123)
    keyer = Timer(10, check_wait_reply)
    keyer.start()


if __name__ == '__main__':
    check_wait_reply()
    eventlet.wsgi.server(eventlet.listen(('', 3000)), app)
IFCZT
  • 89
  • 8
  • Have you seen the example apps in the python-socketio repository on GitHub? For example this: https://github.com/miguelgrinberg/python-socketio/blob/main/examples/server/wsgi/app.py#L16-L22. – Miguel Grinberg Feb 27 '22 at 15:06
  • It seems that you have the same problem as I have: I have a working python socketio server with working client connections. The server can respond to client requests but I can't make the server push messages on its own: https://stackoverflow.com/questions/71338054/python-send-data-every-10-seconds-via-socket-io – Florian Metzger-Noel Mar 16 '22 at 08:39

1 Answers1

0

I had the same problem and found the answer thanks to Miguel's comment.

Here's the working solution:

sio = socketio.Server(cors_allowed_origins="*")
app = socketio.WSGIApp(sio, static_files={'/': {'content_type': 'text/html', 'filename': 'index.html'}})

def check_wait_reply():
    while True:
        sio.sleep(10)
        sio.emit('message', 123123)


if __name__ == '__main__':
    sio.start_background_task(check_wait_reply)
    eventlet.wsgi.server(eventlet.listen(('', 3000)), app)