5

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)
5
  • Could you edit your post to include a code sample? Commented Jan 9, 2023 at 17:16
  • 1
    @Liz Can I use waitress to serve a flask + flask-socketio app?. Commented Jan 9, 2023 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. Commented Jan 10, 2023 at 11:07
  • 2
    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? Commented Jan 10, 2023 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! Commented Jan 11, 2023 at 9:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.