Skip to content

Commit

Permalink
Fix #983 by saving future and checking for + raising any exceptions (#…
Browse files Browse the repository at this point in the history
…1073) (#1088)

* Fix #983 by saving future and checking for + raising any exceptions

Signed-off-by: Achille Verheye <[email protected]>
Co-authored-by: Achille Verheye <[email protected]>
  • Loading branch information
fujitatomoya and Achllle authored Feb 25, 2023
1 parent 7ceb379 commit 0b19c59
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rclpy/rclpy/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ def __init__(self, num_threads: int = None, *, context: Context = None) -> None:
num_threads = multiprocessing.cpu_count()
except NotImplementedError:
num_threads = 1
self._futures = []
self._executor = ThreadPoolExecutor(num_threads)

def _spin_once_impl(
Expand All @@ -753,6 +754,11 @@ def _spin_once_impl(
pass
else:
self._executor.submit(handler)
self._futures.append(handler)
for future in self._futures: # check for any exceptions
if future.done():
self._futures.remove(future)
future.result()

def spin_once(self, timeout_sec: float = None) -> None:
self._spin_once_impl(timeout_sec)
Expand Down

0 comments on commit 0b19c59

Please sign in to comment.