Skip to content

Commit

Permalink
Fix to #1179 (backport) (#1183)
Browse files Browse the repository at this point in the history
Signed-off-by: KKSTB <[email protected]>
  • Loading branch information
KKSTB authored Oct 11, 2023
1 parent e9bd428 commit 0c1215c
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions rclpy/rclpy/wait_for_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,27 @@ def wait_for_message(
wait_set.clear_entities()

sub = node.create_subscription(msg_type, topic, lambda _: None, 1)
wait_set.add_subscription(sub.handle)
sigint_gc = SignalHandlerGuardCondition(context=context)
wait_set.add_guard_condition(sigint_gc.handle)
try:
wait_set.add_subscription(sub.handle)
sigint_gc = SignalHandlerGuardCondition(context=context)
wait_set.add_guard_condition(sigint_gc.handle)

timeout_nsec = timeout_sec_to_nsec(time_to_wait)
wait_set.wait(timeout_nsec)
timeout_nsec = timeout_sec_to_nsec(time_to_wait)
wait_set.wait(timeout_nsec)

subs_ready = wait_set.get_ready_entities('subscription')
guards_ready = wait_set.get_ready_entities('guard_condition')
subs_ready = wait_set.get_ready_entities('subscription')
guards_ready = wait_set.get_ready_entities('guard_condition')

if guards_ready:
if sigint_gc.handle.pointer in guards_ready:
return (False, None)
if guards_ready:
if sigint_gc.handle.pointer in guards_ready:
return False, None

if subs_ready:
if sub.handle.pointer in subs_ready:
msg_info = sub.handle.take_message(sub.msg_type, sub.raw)
if msg_info is not None:
return (True, msg_info[0])
if subs_ready:
if sub.handle.pointer in subs_ready:
msg_info = sub.handle.take_message(sub.msg_type, sub.raw)
if msg_info is not None:
return True, msg_info[0]
finally:
node.destroy_subscription(sub)

return (False, None)
return False, None

0 comments on commit 0c1215c

Please sign in to comment.