From e6cf9c97d0cc5faf7bf04cd4c527c12bffbb9815 Mon Sep 17 00:00:00 2001 From: azhengzz <820108271@qq.com> Date: Tue, 11 May 2021 10:51:03 +0800 Subject: [PATCH] =?UTF-8?q?Flask-SocketIO=E6=B7=BB=E5=8A=A0async=5Fmode=3D?= =?UTF-8?q?'gevent'=E7=9A=84=E5=90=AF=E5=8A=A8=E6=96=B9=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4monkey=5Fpatch=E6=89=A7=E8=A1=8C=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ApiAutomationTest/app/__init__.py | 3 --- ApiAutomationTest/app/extensions.py | 10 +++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ApiAutomationTest/app/__init__.py b/ApiAutomationTest/app/__init__.py index 20ca511..9a108fb 100644 --- a/ApiAutomationTest/app/__init__.py +++ b/ApiAutomationTest/app/__init__.py @@ -17,9 +17,6 @@ from app.template_global import (render_to_json, sort_by_order_in_module, sort_b calc_percent, url_for_static) from app.cores.ws import register_all_user_socket -import eventlet -eventlet.monkey_patch() - def create_app(config_class=Config): app = Flask(import_name=__name__) diff --git a/ApiAutomationTest/app/extensions.py b/ApiAutomationTest/app/extensions.py index 466612a..91277e8 100644 --- a/ApiAutomationTest/app/extensions.py +++ b/ApiAutomationTest/app/extensions.py @@ -22,7 +22,15 @@ login_manager.login_message = "请先登录" mail = Mail() csrf = CSRFProtect() bootstrap = Bootstrap() -socketio = SocketIO(async_mode='eventlet') +# 支持后台线程发送,并被前端接收到 +async_mode = 'eventlet' +if async_mode == 'eventlet': + import eventlet + eventlet.monkey_patch() +elif async_mode == 'gevent': + from gevent import monkey + monkey.patch_all() +socketio = SocketIO(async_mode=async_mode) session_id_manager = SessionIDManager() dispatcher_scheduler = DispatcherScheduler()