1

I have a Flask application that won't run when gevent is installed.

Here is my app.py file:

from app import create_app, socketio

app = create_app()

if __name__ == '__main__':
    socketio.run(app)

init.py (with create_app)

from flask_socketio import SocketIO
...

socketio = SocketIO()

def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(Config)

    socketio.init_app(app, cors_allowed_origins='*')

    ...

    return app

When I run python app.py, this is what shows in terminal:

 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 189-464-699

With this running, my application (localhost:5000/) will not load any page- it just says Internal Server Error, even if it's not a page that uses websocket. I don't see any requests in terminal as I usually would.

What I expect when I run python app.py

 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 335-570-116

and of course I expect to be able to load site pages.

If I uninstall gevent, I can get the expected behavior, however, I get this error: WebSocket transport not available. Install simple-websocket for improved performance.

simple-websocket is already installed. I took this error to mean I should install gevent and gevent-websocket.

With gevent uninstalled, I can load pages, but I receive the above transport not available error in the terminal, and the site pages that use websockets have this error in the debugger: VM78:1 GET http://localhost:5000/socket.io/?EIO=4&transport=polling&t=Ne0kF52 net::ERR_CONNECTION_REFUSED

Dr. Funkenstein
  • 416
  • 4
  • 14
  • Sounds like you are launching a process that you want ASYNC but is running SYNC instead. Nothing in your post indicates gevent. Unless you were monkey patching before. – eatmeimadanish Jun 15 '21 at 20:03
  • You probably need to monkey patch: http://www.gevent.org/api/gevent.monkey.html – David K. Hess Jun 16 '21 at 18:04

1 Answers1

0

for development environment while using socketio.run(app), its better using eventlet.

Daniel Paul
  • 495
  • 1
  • 6
  • 13