Skip to content

Commit

Permalink
High-Latency networks: "generator already executing" when calling a s…
Browse files Browse the repository at this point in the history
…ervice

  ref: ros2/rclpy#1351

Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed Sep 4, 2024
1 parent b1216b6 commit 1598c6b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions prover_rclpy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
'rclpy_1273 = src.rclpy_1273:main',
'rclpy_1287 = src.rclpy_1287:main',
'rclpy_1303 = src.rclpy_1303:main',
'rclpy_1351 = src.rclpy_1351:main',
'ros2cli_818 = src.ros2cli_818:main',
'ros2cli_862 = src.ros2cli_862:main',
'ros2cli_885 = src.ros2cli_885:main',
Expand Down
37 changes: 37 additions & 0 deletions prover_rclpy/src/rclpy_1351.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import threading
import time

import rclpy
from rclpy.executors import Executor
from rclpy.executors import MultiThreadedExecutor
from rclpy.executors import SingleThreadedExecutor
from rclpy.task import Future


def main(args=None):
rclpy.init(args=args)
executor = SingleThreadedExecutor()

future1 = Future(executor=executor)
future2 = Future(executor=executor)

# I believe that we need to use ThreadPoolExecutor here...
thread1 = threading.Thread(target=executor.spin_until_future_complete,
args=(future1, 10))
thread2 = threading.Thread(target=executor.spin_until_future_complete,
args=(future2, 10))

thread1.start()
time.sleep(0.5)
thread2.start()

future1.set_result(True)
future2.set_result(True)

thread1.join()
thread2.join()
executor.shutdown()


if __name__ == '__main__':
main()

0 comments on commit 1598c6b

Please sign in to comment.