From 3226f6343fe28f57b1756347032da4719605ae45 Mon Sep 17 00:00:00 2001 From: Mohammad Farzan Date: Sun, 26 Jun 2022 15:38:16 +0430 Subject: [PATCH] Avoid calling send() on awaiting native coroutine objects Signed-off-by: Mohammad Farzan --- rclpy/rclpy/task.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rclpy/rclpy/task.py b/rclpy/rclpy/task.py index 2ed1d6cd4..b90447493 100644 --- a/rclpy/rclpy/task.py +++ b/rclpy/rclpy/task.py @@ -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 @@ -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()