From 8e21bb046e0311f49b0e24ff54f62c9314cec0e3 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 10 Oct 2021 16:43:32 -0400 Subject: [PATCH] Add `Portal.cancel_called` --- tractor/_portal.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tractor/_portal.py b/tractor/_portal.py index e9ee7aa..b73f4a3 100644 --- a/tractor/_portal.py +++ b/tractor/_portal.py @@ -84,6 +84,15 @@ class Portal: ] = None self._streams: Set[ReceiveMsgStream] = set() self.actor = current_actor() + self._cancel_called: bool = False + + @property + def cancel_called(self) -> bool: + ''' + Same principle as ``trio.CancelScope.cancel_called``. + + ''' + return self._cancel_called async def _submit( self, @@ -197,9 +206,16 @@ class Portal: # we'll need to .aclose all those channels here await self._cancel_streams() - async def cancel_actor(self): - """Cancel the actor on the other end of this portal. - """ + async def cancel_actor(self) -> None: + ''' + Cancel the actor on the other end of this portal. + + That means cancelling the "actor runtime" not just any one + task that's running there. + + ''' + self._cancel_called = True + if not self.channel.connected(): log.cancel("This portal is already closed can't cancel") return False @@ -207,8 +223,8 @@ class Portal: await self._cancel_streams() log.cancel( - f"Sending actor cancel request to {self.channel.uid} on " - f"{self.channel}") + f"Sending runtime cancel msg to {self.channel.uid} @ " + f"{self.channel.raddr}") try: # send cancel cmd - might not get response # XXX: sure would be nice to make this work with a proper shield