Skip to content

Commit

Permalink
Avoid calling send() on awaiting native coroutine objects
Browse files Browse the repository at this point in the history
Signed-off-by: Mohammad Farzan <[email protected]>
  • Loading branch information
m2-farzan committed Jun 26, 2022
1 parent bce7e89 commit 3226f63
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rclpy/rclpy/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def __init__(self, handler, args=None, kwargs=None, executor=None):
self._handler = handler(*args, **kwargs)
self._args = None
self._kwargs = None
self._future = None
# True while the task is being executed
self._executing = False
# Lock acquired to prevent task from executing in parallel with itself
Expand All @@ -236,7 +237,10 @@ def __call__(self):
if inspect.iscoroutine(self._handler):
# Execute a coroutine
try:
self._handler.send(None)
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)
except StopIteration as e:
# The coroutine finished; store the result
self._handler.close()
Expand Down

0 comments on commit 3226f63

Please sign in to comment.