Flask-SocketIO: Flask apps not using Flask-SocketIO get exception/ValueError
Flask apps without use of Flask-SocketIO seem to get a ValueError after just typing flask run in terminal.
Example application code:
import os
from flask import Flask
app = Flask(__name__)
app.config["SECRET_KEY"] = 'secret!'
@app.route("/")
def index():
print('hello world')
return 'hello!'
if __name__ == '__main__':
app.run(debug=True)
Terminal log:
flask run
* Serving Flask-SocketIO app "application.py"
* Forcing debug mode on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 289-305-673
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\site-packages\flask_socketio\cli.py", line 59, in run_server
return run_command()
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\site-packages\click\decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\site-packages\flask\cli.py", line 771, in run_command
threaded=with_threads, ssl_context=cert)
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\site-packages\werkzeug\serving.py", line 812, in run_simple
reloader_type)
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\site-packages\werkzeug\_reloader.py", line 267, in run_with_reloader
signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
File "c:\users\daniel\appdata\local\programs\python\python37-32\lib\signal.py", line 47, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
It seems like with Flask-SocketIO installed, a Flask-SocketIO app is always being run even if the application doesn’t import Flask-SocketIO. So this issue doesn’t occur with flask run with Flask-SocketIO applications, but now occurs with all other Flask applications I’ve written without Flask-SocketIO. I’m not sure if this is an issue with Flask or Flask-SocketIO.
The one workaround I have is to just type python application.py in command line. Any other suggestions for running the non-SocketIO applications would be appreciated. Thanks!
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22 (10 by maintainers)
Commits related to this issue
- Removed eventlet (https://github.com/miguelgrinberg/Flask-SocketIO/issues/817) — committed to swiewiora/python-webshell by deleted user 5 years ago
@dcsan you can use debug mode to enable the reloader:
Hello, I work with VS Code and don’t know how to make it launch with socket.run(app) ?
I’m struggling integrate flask-socketio to my current project, I always have this screen :
EDIT
Seems like add --no-reload like you suggest in an other issue works.
The lines from my last comment were displayed after running
pip install --upgrade flask-socketio. I assumed this would show you the versions of all relevant packages and would be up to date. Sorry for the confusion.However, after checking
pip list --outdatedI did find that python-engineio was outdated. Here is what I now see after upgrading all outdated packages. Runningpip install --upgrade flask-socketionow shows the following:However, I still get the error. Is there something else that’s outdated?
Just to make sure, here is my full pip list
Hey guys, I was also facing the same problem. So to summarize, if you’re using socket-io, don’t do flask run. First, add
at the end of your application. To run it just do
Hope it helped.
@Senseikaii you may also want to add
"gevent": trueto your vscode configuration if you are using gevent or eventlet. Yes, even if you use eventlet the option is calledgevent.The list is incomplete. Run
pip install --upgrade flask-socketioto get all the latest and report back if there are still issues.