forked from goodboy/tractor
1
0
Fork 0

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).
faster_daemon_cancels
Tyler Goodlet 2021-11-20 12:56:38 -05:00
parent f32ccd76aa
commit 095c94b1d2
1 changed files with 3 additions and 2 deletions

View File

@ -77,7 +77,7 @@ class Portal:
# when this is set to a tuple returned from ``_submit()`` then # when this is set to a tuple returned from ``_submit()`` then
# it is expected that ``result()`` will be awaited at some point # it is expected that ``result()`` will be awaited at some point
# during the portal's lifetime # during the portal's lifetime
self._result: Optional[Any] = None self._result: Optional[Any] = channel.uid
# set when _submit_for_result is called # set when _submit_for_result is called
self._expect_result: Optional[ self._expect_result: Optional[
Tuple[str, Any, str, Dict[str, Any]] Tuple[str, Any, str, Dict[str, Any]]
@ -128,6 +128,7 @@ class Portal:
recv_chan: trio.abc.ReceiveChannel, recv_chan: trio.abc.ReceiveChannel,
resptype: str, resptype: str,
first_msg: dict first_msg: dict
) -> Any: ) -> Any:
assert resptype == 'asyncfunc' # single response assert resptype == 'asyncfunc' # single response
@ -158,7 +159,7 @@ class Portal:
# expecting a "main" result # expecting a "main" result
assert self._expect_result assert self._expect_result
if self._result is None: if self._result is self.channel.uid:
try: try:
self._result = await self._return_once(*self._expect_result) self._result = await self._return_once(*self._expect_result)
except RemoteActorError as err: except RemoteActorError as err: