Eventlet Fails Where Flask Development Server Works Fine #1790
-
I am experiencing an issue whereby when running in the Flask development server everything works perfectly fine, but if I use eventlet, messages are not received and the socket seems to time out, disconnect and reconnect. Here's the gist of my server code (I've omitted the code invoking the # __init__.py
import simplejson
db = flask_sqlalchemy.SQLAlchemy()
api = flask_smorest.Api()
socketio = flask_socketio.SocketIO(json=simplejson, logger=True, engineio_logger=True) # app.py
import flask_cors
import flask
from . import (api, db, socketio)
def get_app():
app = flask.Flask(__name__)
app.config.from_mapping(...)
app.app_context().push()
flask_cors.CORS(app)
# flask_sqlalchemy
db.init_app(app)
db.Model.metadata.reflect(bind=db.engine, extend_existing=True)
# flask_smorest
api.init_app(app)
# omitted register blueprints
#flask_socketio
socketio.init_app(app)
return app
def run(port):
app = get_app()
socketio.run(app, host="0.0.0.0", port=port)
if __name__ == "__main__":
sys.exit(run()) And on the client side class Listen():
def __init__(self)
self.sio = socketio.Client(logger=True)
def run(self):
@self.sio.event
def connect():
log.info("PostgresListen socket connection established")
@self.sio.event
def disconnect():
log.info("PostgresListen socket disconnected")
@self.sio.on("projects")
def onProjectChanged(data):
log.info("PosgresListen project changed")
log.debug(data)
self.postgresEvent.emit(data)
self.sio.connect(nymus.socketAddress) When running with eventlet installed, when the server broadcasts an event I get a pause, then Is there something about this setup that wont work with eventlet? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Are you familiar with using asynchronous frameworks and green threads? If not, I think you shouldn't use eventlet. There are many things that need to be done differently, and many libraries that are incompatible. |
Beta Was this translation helpful? Give feedback.
Are you familiar with using asynchronous frameworks and green threads? If not, I think you shouldn't use eventlet. There are many things that need to be done differently, and many libraries that are incompatible.