MCPcopy Create free account
hub / github.com/AstrBotDevs/AstrBot / _task_wrapper

Method _task_wrapper

astrbot/core/core_lifecycle.py:317–333  ·  view source on GitHub ↗

异步任务包装器, 用于处理异步任务执行中出现的各种异常. Args: task (asyncio.Task): 要执行的异步任务

(self, task: asyncio.Task)

Source from the content-addressed store, hash-verified

315 self.start_time = int(time.time())
316
317 async def _task_wrapper(self, task: asyncio.Task) -> None:
318 """异步任务包装器, 用于处理异步任务执行中出现的各种异常.
319
320 Args:
321 task (asyncio.Task): 要执行的异步任务
322
323 """
324 try:
325 await task
326 except asyncio.CancelledError:
327 pass # 任务被取消, 静默处理
328 except Exception as e:
329 # 获取完整的异常堆栈信息, 按行分割并记录到日志中
330 logger.error(f"------- 任务 {task.get_name()} 发生错误: {e}")
331 for line in traceback.format_exc().split("\n"):
332 logger.error(f"| {line}")
333 logger.error("-------")
334
335 async def start(self) -> None:
336 """启动 AstrBot 核心生命周期管理类.

Calls 1

errorMethod · 0.45