Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions rclpy/rclpy/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def spin_until_future_complete(
and not future.cancelled()
and not self._is_shutdown
):
self.spin_once_until_future_complete(future, timeout_sec)
self._spin_once_until_future_complete(future, timeout_sec)
else:
start = time.monotonic()
end = start + timeout_sec
Expand All @@ -339,7 +339,7 @@ def spin_until_future_complete(
and not future.cancelled()
and not self._is_shutdown
):
self.spin_once_until_future_complete(future, timeout_left)
self._spin_once_until_future_complete(future, timeout_left)
now = time.monotonic()

if now >= end:
Expand Down Expand Up @@ -377,6 +377,13 @@ def spin_once_until_future_complete(
"""
raise NotImplementedError()

def _spin_once_until_future_complete(
self,
future: Future,
timeout_sec: Optional[Union[float, TimeoutObject]] = None
) -> None:
raise NotImplementedError()

def _take_timer(self, tmr):
try:
with tmr.handle:
Expand Down Expand Up @@ -844,13 +851,20 @@ def _spin_once_impl(
def spin_once(self, timeout_sec: Optional[float] = None) -> None:
self._spin_once_impl(timeout_sec)

def _spin_once_until_future_complete(
self,
future: Future,
timeout_sec: Optional[Union[float, TimeoutObject]] = None
) -> None:
self._spin_once_impl(timeout_sec, future.done)

def spin_once_until_future_complete(
self,
future: Future,
timeout_sec: Optional[Union[float, TimeoutObject]] = None
) -> None:
future.add_done_callback(lambda x: self.wake())
self._spin_once_impl(timeout_sec, future.done)
self._spin_once_until_future_complete(future, timeout_sec)


class MultiThreadedExecutor(Executor):
Expand Down Expand Up @@ -916,10 +930,17 @@ def _spin_once_impl(
def spin_once(self, timeout_sec: Optional[float] = None) -> None:
self._spin_once_impl(timeout_sec)

def _spin_once_until_future_complete(
self,
future: Future,
timeout_sec: Optional[Union[float, TimeoutObject]] = None
) -> None:
self._spin_once_impl(timeout_sec, future.done)

def spin_once_until_future_complete(
self,
future: Future,
timeout_sec: Optional[Union[float, TimeoutObject]] = None
) -> None:
future.add_done_callback(lambda x: self.wake())
self._spin_once_impl(timeout_sec, future.done)
self._spin_once_until_future_complete(future, timeout_sec)