forked from M-Labs/artiq
tools: Wrap Task _do() calls in a generic exception handler
Signed-off-by: Charles Baynham <charles.baynham@npl.co.uk>
This commit is contained in:
parent
e50a6d5aaf
commit
0b1fb255a9
@ -240,7 +240,16 @@ async def asyncio_wait_or_cancel(fs, **kwargs):
|
|||||||
|
|
||||||
class TaskObject:
|
class TaskObject:
|
||||||
def start(self):
|
def start(self):
|
||||||
self.task = asyncio.ensure_future(self._do())
|
async def log_exceptions(awaitable):
|
||||||
|
try:
|
||||||
|
return await awaitable()
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
raise
|
||||||
|
except Exception:
|
||||||
|
logger.error("Unhandled exception in TaskObject task body", exc_info=True)
|
||||||
|
raise
|
||||||
|
|
||||||
|
self.task = asyncio.ensure_future(log_exceptions(self._do))
|
||||||
|
|
||||||
async def stop(self):
|
async def stop(self):
|
||||||
self.task.cancel()
|
self.task.cancel()
|
||||||
|
Loading…
Reference in New Issue
Block a user