Skip to content

Commit

Permalink
feat: (wip) 支持Python 3.6 / 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
helloplhm-qwq committed Dec 30, 2023
1 parent 177273d commit 18fd6a4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ python main.py # 运行项目

### 直接部署

环境要求:Python 3.8+
没有其他限制,能用 Python 理论上就能跑起来
如果需要部署 flask 版本,请将 main.py 自行换成 main-flask.py
环境要求:Python 3.6+, 建议Python 3.8+
没有其他限制,能用 Python 理论上就能跑起来
flask版本即将停止支持,不建议使用
测试版本部署,linux 命令如果为 python3 请自行替换:

```bash
Expand Down
10 changes: 6 additions & 4 deletions common/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ def _read_config(key):
return value
except:
return None

debug_mode = debug_mode if (debug_mode := _read_config("common.debug_mode")) else False
log_length_limit = log_length_limit if (log_length_limit := _read_config("common.log_length_limit")) else 500
log_file = log_file if (not isinstance(log_file := _read_config("common.log_file"), type(None))) else True
_dm = _read_config("common.debug_mode")
_lm = _read_config("common.log_file")
_ll = _read_config("common.log_length_limit")
debug_mode = _dm if (_dm) else False
log_length_limit = _ll if (_ll) else 500
log_file = _lm if (not isinstance(_lm , type(None))) else True
running = True
config = {}
workdir = _os.getcwd()
Expand Down
16 changes: 15 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
# ----------------------------------------
# This file is part of the "lx-music-api-server" project.

import sys

if (sys.version_info.major < 3 or sys.version_info.minor < 6):
print('Python版本过低,请使用Python 3.6+ ')
sys.exit(1)

from common import config
from common import lxsecurity
from common import log
Expand All @@ -31,6 +37,14 @@ def handleResult(dic, status = 200):
logger = log.log("main")
aiologger = log.log('aiohttp_web')

stopEvent = None
if (sys.version_info.minor < 8):
logger.warning('您使用的Python版本已经停止更新,不建议继续使用')
import concurrent
stopEvent = concurrent.futures._base.CancelledError
else:
stopEvent = asyncio.exceptions.CancelledError

def start_checkcn_thread():
threading.Thread(target=Httpx.checkcn).start()

Expand Down Expand Up @@ -147,7 +161,7 @@ async def initMain():
await run_app()
logger.info("服务器启动成功,请按下Ctrl + C停止")
await asyncio.Event().wait() # 等待停止事件
except (KeyboardInterrupt, asyncio.exceptions.CancelledError):
except (KeyboardInterrupt, stopEvent):
pass
except OSError as e:
if str(e).startswith("[Errno 98]"):
Expand Down

0 comments on commit 18fd6a4

Please sign in to comment.