catch exceptions in callbacks
This commit is contained in:
parent
f47d82733c
commit
ce22e26458
1 changed files with 8 additions and 1 deletions
|
@ -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):
|
||||
try:
|
||||
ret = await cb(*args)
|
||||
except Exception:
|
||||
logging.exception("Exception processing callback")
|
||||
ret = None
|
||||
self._tasks[uid].set()
|
||||
self._tasks.pop(uid)
|
||||
return ret
|
||||
|
|
Loading…
Reference in a new issue