1
0
mirror of https://github.com/hjdhnx/dr_py.git synced 2025-04-06 07:44:00 -04:00

升级drpy,尽量保证gevent的兼容性

This commit is contained in:
晚风拂柳颜 2023-06-26 10:40:39 +08:00
parent dc528bd71c
commit ff0f3836e6
4 changed files with 32 additions and 16 deletions

41
app.py

@ -44,33 +44,48 @@ def create_flask_app():
app = create_flask_app()
migrate = Migrate(app, db)
max_version = (3, 11) # 小于3.11的版本(3.6-3.10)
max_version_str = ".".join([str(i) for i in max_version])
now_python_ver = ".".join([str(i) for i in sys.version_info[:3]])
if sys.version_info < (3, 9):
from gevent.pywsgi import WSGIServer
no_error = True
if sys.version_info < max_version:
try:
from gevent.pywsgi import WSGIServer
# from gevent import monkey
# monkey.patch_all() # 多线程,只能放在最开头,import其它包之前
# from gevent import monkey
# monkey.patch_all() # 多线程,只能放在最开头,import其它包之前
from gevent import monkey
monkey.patch_socket() # 开启socket异步
print(f'当前python版本{now_python_ver}为3.9.0及以下,支持gevent')
from gevent import monkey
monkey.patch_socket() # 开启socket异步
print(f'当前python版本{now_python_ver}{max_version_str}及以下,支持gevent')
except Exception as e:
print(f'gevent使用过程中发生了错误:{e}')
no_error = False
else:
print(f'当前python版本{now_python_ver}为3.9.0及以上,不支持gevent')
print(f'当前python版本{now_python_ver}{max_version_str}及以上,不支持gevent')
if __name__ == "__main__":
http_port = int(app.config.get('HTTP_PORT', 5705))
http_host = app.config.get('HTTP_HOST', '0.0.0.0')
threaded = app.config.get('Thread')
threaded = app.config.get('THREAD')
GEVENT = app.config.get('GEVENT')
print(GEVENT)
if threaded is None:
threaded = True
if GEVENT is None:
debug = False
# https://www.zhihu.com/question/64096559
print('threaded:',threaded)
print(f'threaded:{threaded},GEVENT:{GEVENT}')
# if sys.version_info < (3, 9) and not sys.platform.startswith('win'):
if sys.version_info < (3, 9):
use_gevent = sys.version_info < max_version # 是否使用协程
is_debug = (not GEVENT) and sys.platform.startswith('win') # windows开调试模式
print(f'开启调试模式:{is_debug}')
if use_gevent and no_error and not is_debug:
# server = WSGIServer(('0.0.0.0', 5705), app, handler_class=WebSocketHandler,log=app.logger)
# server = WSGIServer(('0.0.0.0', 5705), app, handler_class=WebSocketHandler,log=None)
server = WSGIServer((http_host, http_port), app, log=logger)
server.serve_forever()
else:
app.run(debug=False, host=http_host, port=http_port, threaded=threaded)
app.run(debug=False, host=http_host, port=http_port, threaded=threaded)

@ -56,5 +56,6 @@ JS_PROXY = 'http://localhost:5705/admin/view/=>https://ghproxy.net/https://raw.g
ALI_TOKEN = '' # 适用于初始配置的阿里云token
ENV = '{"bili_cookie":""}' # 自定义环境变量
UPDATE_PROXY = 'https://ghproxy.net/' # 检测升级代理
Thread = True # 开启windows多线程调用
THREAD = True # 开启windows多线程调用
GEVENT = False # windows开启此参数就不走gevent,方便调试
SPECIAL = '腾云驾雾:腾讯&奇珍异兽:爱奇艺&百忙无果:芒果&优酷&哔哩影视&Alist' # 特殊优选

@ -1 +1 @@
{"showTime":89200000,"txt":"drpy 3.9.43beta18 -道长"}
{"showTime":89200000,"txt":"drpy 3.9.44beta1 -道长"}

@ -1 +1 @@
3.9.43beta18
3.9.44beta1