update pay ui

This commit is contained in:
2025-12-11 21:34:20 +08:00
parent 56e980f19d
commit 54c4f64a49
3 changed files with 246 additions and 19 deletions

41
app.py
View File

@@ -1,13 +1,27 @@
# ============ Gevent Monkey Patching必须放在所有 import 之前!)============
# 用于支持 Gunicorn + gevent 异步模式,使 requests 等阻塞调用变为非阻塞
# 注意:如果使用 GeventWebSocketWorkerworker 会自动 patch这里检测避免重复
import os
if os.environ.get('GEVENT_SUPPORT', 'true').lower() == 'true':
import sys
def _is_already_patched():
"""检测是否已经被 gevent patch"""
try:
from gevent import monkey
monkey.patch_all()
print("✅ Gevent monkey patching 已启用")
return monkey.is_module_patched('socket')
except:
return False
# 只在未被 patch 且明确启用时才 patch
if os.environ.get('GEVENT_SUPPORT', 'false').lower() == 'true' and not _is_already_patched():
try:
from gevent import monkey
monkey.patch_all(thread=False, subprocess=False) # 避免 patch 某些可能有问题的模块
print("✅ Gevent monkey patching 已启用 (手动)")
except ImportError:
print("⚠️ Gevent 未安装,跳过 monkey patching")
elif _is_already_patched():
print("✅ Gevent monkey patching 已由 Worker 启用")
# ============ Gevent Monkey Patching 结束 ============
import base64
@@ -362,11 +376,30 @@ db = SQLAlchemy(app)
mail = Mail(app)
# 初始化 Flask-SocketIO用于实时事件推送
# 自动检测可用的异步模式优先级eventlet > gevent > threading
def _detect_async_mode():
"""检测可用的异步模式"""
try:
import eventlet
return 'eventlet'
except ImportError:
pass
try:
from gevent import monkey
if monkey.is_module_patched('socket'):
return 'gevent'
except ImportError:
pass
return 'gevent' # 默认使用 geventGunicorn 会 patch
_async_mode = _detect_async_mode()
print(f"📡 Flask-SocketIO async_mode: {_async_mode}")
socketio = SocketIO(
app,
cors_allowed_origins=["http://localhost:3000", "http://127.0.0.1:3000", "http://localhost:5173",
"https://valuefrontier.cn", "http://valuefrontier.cn"],
async_mode='gevent',
async_mode=_async_mode,
logger=True,
engineio_logger=False,
ping_timeout=120, # 心跳超时时间客户端120秒内无响应才断开