Flask APP - ValueError: signal only works in main thread

后端 未结 2 1867
时光取名叫无心
时光取名叫无心 2020-12-08 11:13

I try to create a simple flask app:

from flask import Flask

app = Flask(__name__)

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

but when I add

相关标签:
2条回答
  • 2020-12-08 11:26

    The problem you are facing has to do with a bug in the Flask-SocketIO package which replaces the flask run command. Due to this Flask-SocketIO is always used even if you don’t import it. There are several solutions:

    1. Uninstall Flask-SocketIO
    2. Do not use flask run but run the main file of your program
    3. Disable debugging
    4. Disable auto loading if debugging required flask run --no-reload

    Reference to the Flask-SocketIO bug: issue 817

    0 讨论(0)
  • 2020-12-08 11:45

    I solved the problem thanks to @AkshayKumar007 answer on github. That was the most convenient solution for me.

    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

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

    At the end of your application. To run it just do

    python3 __init__.py
    

    Hope it helped.

    0 讨论(0)
提交回复
热议问题