Skip to content
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
4 changes: 4 additions & 0 deletions launch_ros/launch_ros/ros_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(
self.__ros_context = None
self.__ros_node = None
self.__ros_executor = None
self.__ros_executor_thread = None
self.__is_running = False

if autostart:
Expand Down Expand Up @@ -86,8 +87,11 @@ def shutdown(self):
raise RuntimeError('Cannot shutdown a ROS adapter that is not running')
self.__is_running = False
self.__ros_executor_thread.join()
self.__ros_executor.shutdown()
self.__ros_node.destroy_node()
rclpy.shutdown(context=self.__ros_context)
self.__ros_executor_thread = None
self.__ros_node = None

@property
def argv(self):
Expand Down
39 changes: 39 additions & 0 deletions launch_ros/test/test_ros_adapters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2026 ktyang512
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest.mock import patch

from launch_ros.ros_adapters import ROSAdapter


def test_ros_adapter_shutdown_releases_resources():
adapter = ROSAdapter()
old_context = adapter.ros_context
old_executor = adapter.ros_executor

with patch.object(
adapter.ros_executor,
'shutdown',
wraps=adapter.ros_executor.shutdown,
) as executor_shutdown:
adapter.shutdown()

executor_shutdown.assert_called_once_with()
assert adapter.ros_node is None

adapter.start()
assert adapter.ros_context is not old_context
assert adapter.ros_node is not None
assert adapter.ros_executor is not old_executor
adapter.shutdown()