Avoid calling send() on awaiting native coroutine objects#963
Closed
m2-farzan wants to merge 1 commit intoros2:rollingfrom
Closed
Avoid calling send() on awaiting native coroutine objects#963m2-farzan wants to merge 1 commit intoros2:rollingfrom
m2-farzan wants to merge 1 commit intoros2:rollingfrom
Conversation
Signed-off-by: Mohammad Farzan <m2_farzan@yahoo.com>
sloretz
reviewed
Jul 9, 2022
| if self._future is None or self._future.done(): | ||
| if self._future and self._future.exception(): | ||
| raise self._future.exception() | ||
| self._future = self._handler.send(None) |
Contributor
There was a problem hiding this comment.
I don't think this can assume a coroutine will return a future. It seems like the behavior is specific to the async library being used (see #962 (comment)). This change is interesting though because it seems like it would both satisfy an rclpy.Future by calling send(None) until it raised StopIteration, and would only call asyncio.Future.__await__ once.
It still needs a way to wake the executor when an asyncio future completes, and given that asyncio isn't thread safe I bet there would be problems if a multithreaded executor was used.
Contributor
|
I'll close this one in favor of #971 for now. It can be reopened if this ends up looking like a better way forward. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #962
Rationale
If a native coroutine (i.e.
async def) is to be called manually (i.e. usingu = f(); while True: u.send(None), instead ofasyncio.create_task), like in the case of ourTaskclass, then thesendcall should only be done when the coroutine is ready to execute code (i.e. when it has finished anawaitline). This can be examined by storing the future object returned by thesendfunction.Disclaimer
Please review carefully (especially if this is to be backported), as I'm not too confident about the side-effects this one might have. Thanks!