3

I'm using waitress server to deploy the flask app for production. I'm also using flask's socketio along with the eventlet server which requires its own app run.

Currently only serving app on waitress: serve(app, host='0.0.0.0', port=8080)

How do I include the socket.run command for running the socket server? socketio.run(app)

My code: This snippet sets up server for the flask socketio on which it is to be run and in the if name part I serve the app on waitress if in prod mode.

app.py

import eventlet
async_mode = None
if async_mode is None:
    try:
        async_mode = 'eventlet'
    except ImportError:
        pass
if async_mode is None:
    async_mode = 'threading'
print('async_mode is ' + async_mode)
if async_mode == 'eventlet':
    eventlet.monkey_patch()
    socketio = socketIO(app,cors_allowed_origins='*',async_mode=async_mode)

if __name__=='__main__':
    if env_mode=='dev':
        app.run(host='0.0.0.0', port=8080)
    elif env_mode=='prod':
        serve(app, host='0.0.0.0', port=8080)
Liz
  • 31
  • 3
  • Could you edit your post to include a code sample? – Matthew Macri Jan 09 '23 at 17:16
  • 1
    @Liz [Can I use waitress to serve a flask + flask-socketio app?](https://github.com/Pylons/waitress/issues/313). – pjcunningham Jan 09 '23 at 20:45
  • 1
    @MatthewMacri I just did! I'm guessing this is a simple question of being able to serve/run the app on the two servers simultaneously. – Liz Jan 10 '23 at 11:07
  • 1
    Waitress is not a good option for Socket.IO, as it does not support WebSocket. Since you plan on using eventlet, why not use eventlet's own WSGI server instead? – Miguel Grinberg Jan 10 '23 at 15:06
  • 1
    @MiguelGrinberg okay thanks for the feedback! I am mandated to use waitress for reasons. I was wondering if there was a way around it! – Liz Jan 11 '23 at 09:03

0 Answers0