From ce22e264583e68b5109eff34198f7a53cb28d590 Mon Sep 17 00:00:00 2001 From: alemidev Date: Mon, 22 Nov 2021 13:08:31 +0100 Subject: [PATCH] catch exceptions in callbacks --- aiocraft/traits/callbacks.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aiocraft/traits/callbacks.py b/aiocraft/traits/callbacks.py index 06ccba7..8c203ee 100644 --- a/aiocraft/traits/callbacks.py +++ b/aiocraft/traits/callbacks.py @@ -1,5 +1,6 @@ import asyncio import uuid +import logging from typing import Dict, List, Any, Callable @@ -8,6 +9,8 @@ class CallbacksHolder: _callbacks : Dict[Any, List[Callable]] _tasks : Dict[uuid.UUID, asyncio.Event] + _logger : logging.Logger + def __init__(self): super().__init__() self._callbacks = {} @@ -25,7 +28,11 @@ class CallbacksHolder: def _wrap(self, cb:Callable, uid:uuid.UUID) -> Callable: async def wrapper(*args): - ret = await cb(*args) + try: + ret = await cb(*args) + except Exception: + logging.exception("Exception processing callback") + ret = None self._tasks[uid].set() self._tasks.pop(uid) return ret