Skip to content

Use a single executor instance for spinning in client_async_callback. #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ def main(args=None):

try:
node = rclpy.create_node('minimal_client')

executor = rclpy.executors.SingleThreadedExecutor()
executor.add_node(node)

# Node's default callback group is mutually exclusive. This would prevent the client
# response from being processed until the timer callback finished, but the timer callback
# int this example is waiting for the client response
# in this example is waiting for the client response
cb_group = ReentrantCallbackGroup()
cli = node.create_client(AddTwoInts, 'add_two_ints', callback_group=cb_group)
did_run = False
Expand All @@ -55,14 +59,14 @@ async def call_service():
timer = node.create_timer(0.5, call_service, callback_group=cb_group)

while rclpy.ok() and not did_run:
rclpy.spin_once(node)
executor.spin_once()

if did_run:
# call timer callback only once
timer.cancel()

while rclpy.ok() and not did_get_result:
rclpy.spin_once(node)
executor.spin_once()
except KeyboardInterrupt:
pass
except ExternalShutdownException:
Expand Down