18

I am using socket io and flask application.Everthing works except I always get this message. This is my initialization:

app = Flask(__name__)
app.config['SECRET_KEY'] = APP_SECRET_KEY
jwt = JWTManager(app)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
# app.config['transports'] = 'websocket'
socketio = SocketIO(app, cors_allowed_origins="*", async_mode='threading')

socketio.run(app, debug=True)

What may cause this warning and what does it mean?

The console looks like this: enter image description here

  • tried already to install gevent and eventlet and it didn't remove the message
MD10
  • 1,313
  • 3
  • 12
  • 35

3 Answers3

14

If it's the problem occurred when executing a python file Just try pip install eventlet its worked for me you can also try pip install gevent some times this can also do the trick!

benjixinator
  • 129
  • 1
  • 12
SREERAG R NANDAN
  • 593
  • 5
  • 15
9

Normally you do not include the async_mode option when you instantiate your server. By having async_mode='threading' you are forcing the server to ignore eventlet and/or gevent and go with the more basic server, which does not support WebSocket.

So remove async_mode, then install eventlet (or gevent and gevent-websocket). Now your server will have access to WebSocket and will not show the warning.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152
  • If I remove this then the requests block the main thread and the listening to emits doesnt work – MD10 Apr 03 '20 at 17:02
  • Okay, then you will not be able to use eventlet or gevent and consequently your server will not support WebSocket, so it will have downgraded performance, hence the warning. I would try to address the blocking so that you can use WebSocket. – Miguel Grinberg Apr 04 '20 at 09:27
0

pip install simple-websocket

    from flask import Flask
    from flask_socketio import SocketIO, emit


    app = Flask(__name__)
    app.config['SECRET_KEY'] = 'secret!'
    socketio = SocketIO(app, async_mode='threading', transports=['websocket'])

    if __name__ == '__main__':
       socketio.run(app)
kakou
  • 636
  • 2
  • 7
  • 15
pain
  • 1
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 08 '23 at 17:04