问题描述
我有一个 Flask 应用程序,它在安装 gevent 时无法运行.
I have a Flask application that won't run when gevent is installed.
这是我的 app.py 文件:
Here is my app.py file:
from app import create_app, socketio
app = create_app()
if __name__ == '__main__':
socketio.run(app)
init.py(带有 create_app)
init.py (with create_app)
from flask_socketio import SocketIO
...
socketio = SocketIO()
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(Config)
socketio.init_app(app, cors_allowed_origins='*')
...
return app
当我运行 python app.py
时,这是在终端中显示的:
When I run python app.py
, this is what shows in terminal:
* Restarting with stat
* Debugger is active!
* Debugger PIN: 189-464-699
运行此程序后,我的应用程序 (localhost:5000/) 将不会加载任何页面 - 它只会显示 Internal Server Error
,即使它不是使用 websocket 的页面.我没有像往常一样在终端中看到任何请求.
With this running, my application (localhost:5000/) will not load any page- it just says Internal Server Error
, even if it's not a page that uses websocket. I don't see any requests in terminal as I usually would.
我在运行 python app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 335-570-116
当然,我希望能够加载网站页面.
and of course I expect to be able to load site pages.
如果我卸载 gevent,我可以获得预期的行为,但是,我收到此错误:WebSocket 传输不可用.安装 simple-websocket 以提高性能.
If I uninstall gevent, I can get the expected behavior, however, I get this error:
WebSocket transport not available. Install simple-websocket for improved performance.
simple-websocket
已经安装.我认为这个错误意味着我应该安装 gevent
和 gevent-websocket
.
simple-websocket
is already installed. I took this error to mean I should install gevent
and gevent-websocket
.
gevent 卸载后,我可以加载页面,但是我在终端中收到上述transport not available
错误,使用websockets的站点页面在调试器:VM78:1 GET http://localhost:5000/socket.io/?EIO=4&transport=polling&t=Ne0kF52 net::ERR_CONNECTION_REFUSED
With gevent uninstalled, I can load pages, but I receive the above transport not available
error in the terminal, and the site pages that use websockets have this error in the debugger: VM78:1 GET http://localhost:5000/socket.io/?EIO=4&transport=polling&t=Ne0kF52 net::ERR_CONNECTION_REFUSED
推荐答案
对于使用 socketio.run(app) 时的开发环境,最好使用 eventlet.
for development environment while using socketio.run(app), its better using eventlet.