File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -309,8 +309,8 @@ def return_err_msg_response(
309309 err_response_json = ErrRseponseJson (detail = detail )
310310
311311 # TODO: 请注意,logging是同步函数,每次会阻塞1ms左右,这可能会导致性能问题
312- # 特别是对于写入文件的log,最好把它放到 asyncio .to_thread 里执行
313- # https://docs.python.org/zh-cn/3/library/asyncio-task .html#coroutine
312+ # 特别是对于写入文件的log,最好把它放到 `anyio .to_thread.run_sync()` 里执行
313+ # https://anyio.readthedocs.io/en/stable/threads .html#running-a-function-in-a-worker-thread
314314
315315 if logger is not None :
316316 # 只要传入了logger,就一定记录日志
Original file line number Diff line number Diff line change 33The low-level API for [fastapi_proxy_lib.fastapi.app][].
44"""
55
6- import asyncio
76import warnings
87from contextlib import asynccontextmanager
98from typing import (
1817 Union ,
1918)
2019
20+ import anyio
2121from fastapi import APIRouter
2222from starlette .requests import Request
2323from starlette .responses import Response
@@ -273,6 +273,8 @@ async def shutdown_clients(*_: Any, **__: Any) -> AsyncIterator[None]:
273273 When __aexit__ is called, will close all registered proxy.
274274 """
275275 yield
276- await asyncio .gather (* [proxy .aclose () for proxy in self .registered_proxy ])
276+ async with anyio .create_task_group () as tg :
277+ for proxy in self .registered_proxy :
278+ tg .start_soon (proxy .aclose )
277279
278280 return shutdown_clients
You can’t perform that action at this time.
0 commit comments