From 3b8684f655e328bf0385497227a0c0bd2d627bed Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 14 Oct 2020 13:59:57 -0400 Subject: [PATCH] Always call `Actor.cancel()` at end of root's main task It's simpler and the only real logical difference is logging messages. This should also give us an overall consistent tear down sequence. --- tractor/_actor.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tractor/_actor.py b/tractor/_actor.py index 6010a56..178e12a 100644 --- a/tractor/_actor.py +++ b/tractor/_actor.py @@ -1083,19 +1083,12 @@ async def _start_actor( try: result = await main() except (Exception, trio.MultiError) as err: - try: - log.exception("Actor crashed:") - await _debug._maybe_enter_pm(err) + log.exception("Actor crashed:") + await _debug._maybe_enter_pm(err) - raise - - finally: - await actor.cancel() - - # XXX: the actor is cancelled when this context is complete - # given that there are no more active peer channels connected - actor.cancel_server() - actor._service_n.cancel_scope.cancel() + raise + finally: + await actor.cancel() # unset module state _state._current_actor = None