From 095c94b1d2b2192c524a63df285a424f72155712 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 20 Nov 2021 12:56:38 -0500 Subject: [PATCH] Fix `Portal.run_in_actor()` returns `None` bug Fixes the issue where if the main remote task returns `None`, `Portal.result()` would erroneously wait again on the underlying feeder mem chan since `None` was being used as the cache flag. Instead set the flag as the channel uid and consider the result collected when set to anything else (since it would be odd to return that value from a remote task when you already can read it as part of portal/channel apis). --- tractor/_portal.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tractor/_portal.py b/tractor/_portal.py index 382f8e4..e4e11b9 100644 --- a/tractor/_portal.py +++ b/tractor/_portal.py @@ -77,7 +77,7 @@ class Portal: # when this is set to a tuple returned from ``_submit()`` then # it is expected that ``result()`` will be awaited at some point # during the portal's lifetime - self._result: Optional[Any] = None + self._result: Optional[Any] = channel.uid # set when _submit_for_result is called self._expect_result: Optional[ Tuple[str, Any, str, Dict[str, Any]] @@ -128,6 +128,7 @@ class Portal: recv_chan: trio.abc.ReceiveChannel, resptype: str, first_msg: dict + ) -> Any: assert resptype == 'asyncfunc' # single response @@ -158,7 +159,7 @@ class Portal: # expecting a "main" result assert self._expect_result - if self._result is None: + if self._result is self.channel.uid: try: self._result = await self._return_once(*self._expect_result) except RemoteActorError as err: