From 9e7d5f0d7a91d601a4e5db7e5bf651fd18011369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8D=95=E9=A3=8E=E7=9A=84=E9=80=8D=E9=81=A5=E4=BE=AF?= Date: Mon, 27 Oct 2025 23:48:55 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=AE=BE=E7=BD=AEnodejs=20PATH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Start.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Start.py b/Start.py index 3923fd2..9786dc7 100644 --- a/Start.py +++ b/Start.py @@ -10,6 +10,9 @@ import sys import shutil from pathlib import Path +node_bin = '/opt/eric/nodejs/node-v24.1.0-linux-x64/bin' +os.environ['PATH'] = f"{node_bin}:{os.environ.get('PATH', '')}" + # ==================== 在导入任何模块之前先迁移数据库 ==================== def _migrate_database_files_early(): """在启动前检查并迁移数据库文件到data目录(使用print,因为logger还未初始化)""" From cd502a2e2e17142cb8ba7bcb11b9a35075e6c4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8D=95=E9=A3=8E=E7=9A=84=E9=80=8D=E9=81=A5=E4=BE=AF?= Date: Tue, 28 Oct 2025 22:31:33 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Pycharm=20debug=E6=A8=A1=E5=BC=8F=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=20https://gitee.com/aohanhongzhi/xianyu-auto-reply/is?= =?UTF-8?q?sues/ID3UXR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Start.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Start.py b/Start.py index 9786dc7..e7177ad 100644 --- a/Start.py +++ b/Start.py @@ -143,7 +143,23 @@ def _start_api_server(): port = parsed.port or 8080 logger.info(f"启动Web服务器: http://{host}:{port}") - uvicorn.run("reply_server:app", host=host, port=port, log_level="info") + # 在后台线程中创建独立事件循环并直接运行 server.serve() + import uvicorn + try: + config = uvicorn.Config("reply_server:app", host=host, port=port, log_level="info") + server = uvicorn.Server(config) + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + loop.run_until_complete(server.serve()) + except Exception as e: + logger.error(f"uvicorn服务器启动失败: {e}") + try: + # 确保线程内事件循环被正确关闭 + loop = asyncio.get_event_loop() + if loop.is_running(): + loop.stop() + except Exception: + pass @@ -248,4 +264,16 @@ async def main(): if __name__ == '__main__': - asyncio.run(main()) \ No newline at end of file + # 避免使用被monkey patch的asyncio.run() + # 使用原生的事件循环管理方式 + try: + loop = asyncio.get_event_loop() + if loop.is_running(): + # 如果事件循环已经在运行,创建任务 + asyncio.create_task(main()) + else: + # 正常启动事件循环 + loop.run_until_complete(main()) + except RuntimeError: + # 如果没有事件循环,创建一个新的 + asyncio.run(main()) \ No newline at end of file From ac5313ecc173e6e8e36d3fce993ea87cdb28a3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8D=95=E9=A3=8E=E7=9A=84=E9=80=8D=E9=81=A5=E4=BE=AF?= Date: Wed, 29 Oct 2025 10:10:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=8E=BB=E6=8E=89node?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Start.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Start.py b/Start.py index e7177ad..ecf8349 100644 --- a/Start.py +++ b/Start.py @@ -10,9 +10,6 @@ import sys import shutil from pathlib import Path -node_bin = '/opt/eric/nodejs/node-v24.1.0-linux-x64/bin' -os.environ['PATH'] = f"{node_bin}:{os.environ.get('PATH', '')}" - # ==================== 在导入任何模块之前先迁移数据库 ==================== def _migrate_database_files_early(): """在启动前检查并迁移数据库文件到data目录(使用print,因为logger还未初始化)"""