-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
High-Latency networks: "generator already executing" when calling a s…
…ervice ref: ros2/rclpy#1351 Signed-off-by: Tomoya Fujita <[email protected]>
- Loading branch information
1 parent
b1216b6
commit 1598c6b
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |