mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-28 16:20:56 +08:00
chore: cancel only zhenxun tasks on shutdown
This commit is contained in:
@@ -94,14 +94,18 @@ __all__ = [
|
|||||||
|
|
||||||
|
|
||||||
async def cancel_pending_tasks():
|
async def cancel_pending_tasks():
|
||||||
"""在关闭前尽量取消仍在运行的协程,避免关闭后继续访问数据库连接池。"""
|
"""仅取消 zhenxun 业务协程,避免干扰框架的关机流程。"""
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
current = asyncio.current_task(loop=loop)
|
current = asyncio.current_task(loop=loop)
|
||||||
pending = [
|
pending = []
|
||||||
task
|
for task in asyncio.all_tasks(loop):
|
||||||
for task in asyncio.all_tasks(loop)
|
if task is current or task.done():
|
||||||
if task is not current and not task.done()
|
continue
|
||||||
]
|
coro = task.get_coro()
|
||||||
|
module = getattr(coro, "__module__", "")
|
||||||
|
if module.startswith("zhenxun"):
|
||||||
|
pending.append(task)
|
||||||
|
|
||||||
if not pending:
|
if not pending:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user