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 asyncio
|
||||||
import uuid
|
import uuid
|
||||||
|
import logging
|
||||||
|
|
||||||
from typing import Dict, List, Any, Callable
|
from typing import Dict, List, Any, Callable
|
||||||
|
|
||||||
|
@ -8,6 +9,8 @@ class CallbacksHolder:
|
||||||
_callbacks : Dict[Any, List[Callable]]
|
_callbacks : Dict[Any, List[Callable]]
|
||||||
_tasks : Dict[uuid.UUID, asyncio.Event]
|
_tasks : Dict[uuid.UUID, asyncio.Event]
|
||||||
|
|
||||||
|
_logger : logging.Logger
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._callbacks = {}
|
self._callbacks = {}
|
||||||
|
@ -25,7 +28,11 @@ class CallbacksHolder:
|
||||||
|
|
||||||
def _wrap(self, cb:Callable, uid:uuid.UUID) -> Callable:
|
def _wrap(self, cb:Callable, uid:uuid.UUID) -> Callable:
|
||||||
async def wrapper(*args):
|
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[uid].set()
|
||||||
self._tasks.pop(uid)
|
self._tasks.pop(uid)
|
||||||
return ret
|
return ret
|
||||||
|
|
Loading…
Reference in a new issue