When I add flask_socketio into my __init__.py I don't get any errors running flask run but suddenly the debugger PIN is missing and the development server no longer serves requests at http://127.0.0.1:5000. Everything just fails silently.
My FLASK_APP variable is set to the name of my package and FLASK_ENV is set to development.
requirements.txt
click==6.7
Flask==1.0.2
Flask-SocketIO==3.0.2
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
pkg-resources==0.0.0
python-engineio==2.2.0
python-socketio==2.0.0
six==1.11.0
Werkzeug==0.14.1
__init__.py
import os
from flask import Flask
from flask_socketio import SocketIO
socketio = SocketIO()
def create_app(test_config=None):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SECRET_KEY='dev',
DATABASE=os.path.join(app.instance_path, 'garden.sqlite'),
)
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile('config.py', silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
from . import db
db.init_app(app)
from . import auth
app.register_blueprint(auth.bp)
socketio.init_app(app)
return app
console output missing debugger PIN
* Serving Flask-SocketIO app "garden"
* Forcing debug mode on
* Restarting with stat
WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
Installing eventlet via pip install eventlet fixed the issue, and suddenly the development server launches perfectly fine. If I'm not mistaken, the docs mentioned that the development server could run without eventlet and the last console message seems to indicate the same: WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
This is caused by a bug in Flask that was introduced with the 1.0 release. See https://github.com/pallets/flask/issues/2776.
Most helpful comment
Installing
eventletviapip install eventletfixed the issue, and suddenly the development server launches perfectly fine. If I'm not mistaken, the docs mentioned that the development server could run withouteventletand the last console message seems to indicate the same:WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.