From 88011dff6f31887eb822539836c3038a41e4aab9 Mon Sep 17 00:00:00 2001 From: zhangtao <9480807882@qq.com> Date: Sat, 22 Mar 2025 23:51:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(backend):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=E5=87=BD=E6=95=B0=E7=9A=84=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 替换 asyncio.run 为 get_event_loop 和 run_until_complete 方法 - 这种方式在某些情况下可能提供更好的性能和灵活性 修改初始化pg数据库windows报错问题 Exceptionignored in: Traceback(most recent call last):File:\Python310\lib\asyncio\proactor_events.py",line 116,indeluC:File"c:\Python31o\lib\asyncio\proactor_events.py",line 108, in closeFile"c:\Python310\lib\asyncio\base_events.py", "c:\Python31o\lib\asyncio\base_events.py",line 510,in _check_closedFileRuntimeError: EventLoop is closed --- backend/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/main.py b/backend/main.py index 817bac56..0304c397 100755 --- a/backend/main.py +++ b/backend/main.py @@ -64,8 +64,10 @@ def init(env: EnvironmentEnum = typer.Option(EnvironmentEnum.DEV, "--env", help= os.environ["ENVIRONMENT"] = env.value # 初始化数据 data = InitializeData() - # 使用asyncio.run来运行异步函数 - asyncio.run(data.run()) + # 使用asyncio.run来运行异步函数, + loop = asyncio.get_event_loop() + loop.run_until_complete(data.run()) + # asyncio.run(data.run()) @shell_app.command() def revision(message: str, env: EnvironmentEnum = typer.Option(EnvironmentEnum.DEV, "--env", help="运行环境 (dev, test, prod)")):