Skip to content
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

Fix zenoh shutdown #550

Open
wants to merge 2 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
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
33 changes: 17 additions & 16 deletions test_communication/test/action_server_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,22 @@ def execute_goal(goal_handle):
parser.add_argument('namespace', help='namespace of the ROS node')
args = parser.parse_args()

with rclpy.init(args=[]):
node = rclpy.create_node('action_server', namespace=args.namespace)

if 'Fibonacci' == args.action_type:
action_server = receive_goals(node, Fibonacci, generate_expected_fibonacci_goals())
elif 'NestedMessage' == args.action_type:
action_server = receive_goals(
node,
NestedMessage,
generate_expected_nested_message_goals(),
)
else:
print('Unknown action type {!r}'.format(args.action_type), file=sys.stderr)
sys.exit(1)

rclpy.spin(node)
rclpy.init(args=[])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens with zenoh if we use contextmanager manner with InitContextManager? i am not sure if this change is needed here because both call cleanup process through the context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly, this should not be needed. Going forward, our recommended pattern in rclpy is to use the context manager with rclpy.init, so if that is not working, there is a bug somewhere that needs to be fixed.

node = rclpy.create_node('action_server', namespace=args.namespace)

if 'Fibonacci' == args.action_type:
action_server = receive_goals(node, Fibonacci, generate_expected_fibonacci_goals())
elif 'NestedMessage' == args.action_type:
action_server = receive_goals(
node,
NestedMessage,
generate_expected_nested_message_goals(),
)
else:
print('Unknown action type {!r}'.format(args.action_type), file=sys.stderr)
sys.exit(1)

rclpy.spin(node)
rclpy.shutdown()
except (KeyboardInterrupt, ExternalShutdownException):
print('Action server stopped cleanly')
27 changes: 14 additions & 13 deletions test_communication/test/replier_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,24 @@ def replier(service_name, number_of_cycles, namespace):
module = importlib.import_module(service_pkg + '.srv')
srv_mod = getattr(module, service_name)

with rclpy.init(args=[]):
node = rclpy.create_node('replier', namespace=namespace)
rclpy.init(args=[])
node = rclpy.create_node('replier', namespace=namespace)

srv_fixtures = get_test_srv(service_name)
srv_fixtures = get_test_srv(service_name)

chatter_callback = functools.partial(
replier_callback, srv_fixtures=srv_fixtures)
chatter_callback = functools.partial(
replier_callback, srv_fixtures=srv_fixtures)

node.create_service(
srv_mod, 'test/service/' + service_name, chatter_callback)
node.create_service(
srv_mod, 'test/service/' + service_name, chatter_callback)

spin_count = 1
print('replier: beginning loop')
while rclpy.ok() and spin_count < number_of_cycles:
rclpy.spin_once(node, timeout_sec=2)
spin_count += 1
print('spin_count: ' + str(spin_count))
spin_count = 1
print('replier: beginning loop')
while rclpy.ok() and spin_count < number_of_cycles:
rclpy.spin_once(node, timeout_sec=2)
spin_count += 1
print('spin_count: ' + str(spin_count))
rclpy.shutdown()


if __name__ == '__main__':
Expand Down
33 changes: 17 additions & 16 deletions test_communication/test/subscriber_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,28 @@ def listener(msg_name, namespace):
module = importlib.import_module(message_pkg + '.msg')
msg_mod = getattr(module, msg_name)

with rclpy.init(args=[]):
node = rclpy.create_node('listener', namespace=namespace)
rclpy.init(args=[])
node = rclpy.create_node('listener', namespace=namespace)

received_messages = []
expected_msgs = [(i, repr(msg)) for i, msg in enumerate(get_test_msg(msg_name))]
received_messages = []
expected_msgs = [(i, repr(msg)) for i, msg in enumerate(get_test_msg(msg_name))]

chatter_callback = functools.partial(
listener_cb, received_messages=received_messages, expected_msgs=expected_msgs)
chatter_callback = functools.partial(
listener_cb, received_messages=received_messages, expected_msgs=expected_msgs)

node.create_subscription(
msg_mod, 'test/message/' + msg_name, chatter_callback, 10)
node.create_subscription(
msg_mod, 'test/message/' + msg_name, chatter_callback, 10)

spin_count = 1
print('subscriber: beginning loop')
while (rclpy.ok() and len(received_messages) != len(expected_msgs)):
rclpy.spin_once(node)
spin_count += 1
print('spin_count: ' + str(spin_count))
spin_count = 1
print('subscriber: beginning loop')
while (rclpy.ok() and len(received_messages) != len(expected_msgs)):
rclpy.spin_once(node)
spin_count += 1
print('spin_count: ' + str(spin_count))

assert len(received_messages) == len(expected_msgs), \
'Should have received {} {} messages from talker'.format(len(expected_msgs), msg_name)
assert len(received_messages) == len(expected_msgs), \
'Should have received {} {} messages from talker'.format(len(expected_msgs), msg_name)
rclpy.shutdown()


if __name__ == '__main__':
Expand Down