Skip to content

Commit

Permalink
rclpy_1351 uses ThreadPoolExecutor
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed Sep 5, 2024
1 parent e0e02a7 commit cdb2440
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions prover_rclpy/src/rclpy_1351.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import threading
import time

from concurrent.futures import ThreadPoolExecutor

import rclpy
from rclpy.executors import Executor
from rclpy.executors import MultiThreadedExecutor
Expand All @@ -16,20 +18,27 @@ def main(args=None):
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 = threading.Thread(target=executor.spin_until_future_complete, args=(future1, 10))
#thread2 = threading.Thread(target=executor.spin_until_future_complete, args=(future2, 10))

# rolling does not fail with this...
with ThreadPoolExecutor(max_workers=5) as exe:
exe.submit(executor.spin_until_future_complete, future1, 10)
exe.submit(executor.spin_until_future_complete, future2, 10)

time.sleep(1.0)
future1.set_result(True)
future2.set_result(True)

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

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

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


Expand Down

0 comments on commit cdb2440

Please sign in to comment.