Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why override flask run? #713

Closed
maxnoe opened this issue Jun 1, 2018 · 18 comments
Closed

Why override flask run? #713

maxnoe opened this issue Jun 1, 2018 · 18 comments
Assignees
Labels

Comments

@maxnoe
Copy link

maxnoe commented Jun 1, 2018

This was really unexpected to me. Just having flask-socketio installed breaks FLASK_DEBUG=true because it overrides the flask run command.

Why is this done and is this really necessary?

@miguelgrinberg
Copy link
Owner

It isn't supposed to break anything. Can you describe what is the problem that you found?

The reason flask run is overriden is that Flask-SocketIO tries to use a web server that supports WebSocket if available.

@maxnoe
Copy link
Author

maxnoe commented Jun 2, 2018

See pallets/flask#2200

@miguelgrinberg
Copy link
Owner

@maxnoe I can't reproduce that error with latest versions of Flask and Flask-SocketIO and my own test application. Do you have a simple example I can try here, and the output of pip freeze in your virtual environment? I hope that should be enough for me to reproduce this problem.

@maxnoe
Copy link
Author

maxnoe commented Jun 3, 2018

$ pip freeze
click==6.7
Flask==1.0.2
Flask-SocketIO==3.0.0
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
python-engineio==2.1.1
python-socketio==1.9.0
six==1.11.0
Werkzeug==0.14.1

Having this issue inside a minimal installation using pipenv and only flask and flask_socketio with the flask hello world app.

@miguelgrinberg
Copy link
Owner

Oh, so you installed Flask-SocketIO in your virtualenv but are not using it in the application?

@maxnoe
Copy link
Author

maxnoe commented Jun 3, 2018

Yes, pretty uncommon, I know. But nevertheless unexpected.

@maxnoe
Copy link
Author

maxnoe commented Jun 3, 2018

I ran into this, when I started a new Project and intstalled flask_socketio but wasn't using it yet.

@miguelgrinberg
Copy link
Owner

Should be fixed in release 3.0.1.

@miguelgrinberg
Copy link
Owner

This fix was undone, as it affects the operation of the reloader for normal apps. Will need to find a different way to address this problem.

@miguelgrinberg miguelgrinberg self-assigned this Sep 12, 2018
@Kamforka
Copy link

Have the same issue. It's quite unorthodox for a pip install to break my app :D

@miguelgrinberg
Copy link
Owner

@Kamforka yes, I apologize for that. This used to work fine with Flask < 1.0 versions, but some changes that went into that release are incompatible with my solution.

@Kamforka
Copy link

@miguelgrinberg is the fix in progress or you welcome contributors to sort it out?

@miguelgrinberg
Copy link
Owner

This isn't at the top of my list at this time, given that it has a very easy workaround (i.e. uninstall Flask-SocketIO if you are not using it!). You are welcome to look into it.

@GlennG2012
Copy link

Hey, I don't know if this helps. But rather than installing/uninstalling flask-socketio, place if name == 'main': socketio.run(app) on applications that uses it, and then app.run() on those that don't. rather than flask run, do 'python application.py' on terminal instead

@Kamforka
Copy link

Kamforka commented Jan 16, 2019

@GlennG2012 thanks for the suggestion, however our deployment relies on flask run and it was causing problem during the onboarding of Flask-SocketIO whereas on one branch we had an app without socketio and on an other we had with socketio and of course the package was already installed in the virtual environment. Now that those branches - without socketio - are extinct it's not a huge deal any more, just inconvenient for a fresh start.

@miguelgrinberg
Copy link
Owner

Starting with Flask-SocketIO 3.2.0 (just released), the flask run command can only be used with the threading mode. For all other async modes, the socketio.run(app) method should be used to start the server.

@Kamforka
Copy link

Is it necessary to drop compatibility with complex applications which use the .init_app() method to setup extensions?
Isn't there a way to check in the modified flask run if the app has a registered socket io extension?

@miguelgrinberg
Copy link
Owner

@Kamforka that can all be done. What cannot be done easily is to pass through control from my modified run to the original run in the cases where this is necessary. I can't also automatically change my modified run function to match changes made to the Flask run command. When this happens my function breaks and I need to put out the fire. It brings me a lot of unhappiness, and all to support a way of starting the server that I don't even like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants