catch exceptions from Worker.run

This commit is contained in:
lilydjwg 2022-08-12 13:40:33 +08:00
parent 8b8f2d1d8a
commit 9ee53041b6
2 changed files with 8 additions and 1 deletions

View File

@ -259,7 +259,7 @@ class Dispatcher:
func = mod.get_version func = mod.get_version
ctx.run(worker.initialize, func) ctx.run(worker.initialize, func)
ret.append(ctx.run(worker.run)) ret.append(ctx.run(worker._run_maynot_raise))
return ret return ret

View File

@ -146,6 +146,13 @@ class BaseWorker:
'''Run the `tasks`. Subclasses should implement this method.''' '''Run the `tasks`. Subclasses should implement this method.'''
raise NotImplementedError raise NotImplementedError
async def _run_maynot_raise(self) -> None:
try:
await self.run()
except Exception:
# don't let an exception tear down the whole process
logger.exception('exception raised by Worker.run')
class AsyncCache: class AsyncCache:
'''A cache for use with async functions.''' '''A cache for use with async functions.'''
cache: Dict[Hashable, Any] cache: Dict[Hashable, Any]