Skip to content

Specified __del__ method does not get called after importing sensor_msgs.msg.Imu while having a timer callback #1533

@Aeyu17

Description

@Aeyu17

Generated by Generative AI

No response

Operating System:

spongebob-Precision-3660 6.8.0-85-generic #85~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 19 16:18:59 UTC 2 x86_64 x86_64 x86_64 GNU/LinuxLinux

ROS version or commit hash:

humble

RMW implementation (if applicable):

rmw_fastrtps_cpp

RMW Configuration (if applicable):

No response

Client library (if applicable):

rclpy

'ros2 doctor --report' output

ros2 doctor --report
   NETWORK CONFIGURATION
[REDACTED FOR PRIVACY]

   PACKAGE VERSIONS
quality_of_service_demo_cpp               : latest=0.20.6, local=0.20.5
ament_cmake_cppcheck                      : latest=0.12.14, local=0.12.14
sros2_cmake                               : latest=0.10.7, local=0.10.7
rmw_dds_common                            : latest=1.6.0, local=1.6.0
tf2_kdl                                   : latest=0.25.17, local=0.25.16
zed_msgs                                  : latest=5.1.1, local=5.0.1
rqt_py_console                            : latest=1.0.2, local=1.0.2
launch_yaml                               : latest=1.0.12, local=1.0.10
rosidl_typesupport_introspection_cpp      : latest=3.1.7, local=3.1.7
angles                                    : latest=1.15.0, local=1.15.0
examples_rclcpp_multithreaded_executor    : latest=0.15.5, local=0.15.4
rqt_action                                : latest=2.0.1, local=2.0.1
rmw_fastrtps_cpp                          : latest=6.2.9, local=6.2.8
robot_state_publisher                     : latest=3.0.3, local=3.0.3
ros2launch                                : latest=0.19.12, local=0.19.12
interactive_markers                       : latest=2.3.2, local=2.3.2
launch_ros                                : latest=0.19.12, local=0.19.12
python_qt_binding                         : latest=1.1.3, local=1.1.2
rcl_yaml_param_parser                     : latest=5.3.11, local=5.3.10
pluginlib                                 : latest=5.1.2, local=5.1.0
quality_of_service_demo_py                : latest=0.20.6, local=0.20.5
rqt_plot                                  : latest=1.1.5, local=1.1.5
examples_rclpy_minimal_action_client      : latest=0.15.5, local=0.15.4
vision_msgs                               : latest=4.1.1, local=4.1.1
class_loader                              : latest=2.2.0, local=2.2.0
rosbag2_storage                           : latest=0.15.15, local=0.15.15
std_msgs                                  : latest=4.9.0, local=4.9.0
builtin_interfaces                        : latest=1.2.2, local=1.2.2
ament_cmake_export_link_flags             : latest=1.3.12, local=1.3.12
pybind11_vendor                           : latest=2.4.2, local=2.4.2
tf2_tools                                 : latest=0.25.17, local=0.25.16
rcutils                                   : latest=5.1.7, local=5.1.7
ros_environment                           : latest=3.2.2, local=3.2.2
ament_cmake_gmock                         : latest=1.3.12, local=1.3.12
rosidl_cmake                              : latest=3.1.7, local=3.1.7
ament_cmake_include_directories           : latest=1.3.12, local=1.3.12
ament_cmake_export_interfaces             : latest=1.3.12, local=1.3.12
rosbag2_compression_zstd                  : latest=0.15.15, local=0.15.15
examples_rclcpp_minimal_composition       : latest=0.15.5, local=0.15.4
lifecycle                                 : latest=0.20.6, local=0.20.5
rviz_assimp_vendor                        : latest=11.2.22, local=11.2.20
ros2component                             : latest=0.18.14, local=0.18.14
tf2_msgs                                  : latest=0.25.17, local=0.25.16
rosbag2                                   : latest=0.15.15, local=0.15.15
ament_cmake_python                        : latest=1.3.12, local=1.3.12
action_msgs                               : latest=1.2.2, local=1.2.2
fastrtps_cmake_module                     : latest=2.2.3, local=2.2.2
tinyxml2_vendor                           : latest=0.7.6, local=0.7.6
tf2                                       : latest=0.25.17, local=0.25.16
ament_cmake_xmllint                       : latest=0.12.14, local=0.12.14
message_filters                           : latest=4.3.11, local=4.3.8
ros2multicast                             : latest=0.18.14, local=0.18.14
ament_cmake_flake8                        : latest=0.12.14, local=0.12.14
rosidl_adapter                            : latest=3.1.7, local=3.1.7
pendulum_msgs                             : latest=0.20.6, local=0.20.5
qt_dotgraph                               : latest=2.2.4, local=2.2.4
rclcpp_components                         : latest=16.0.15, local=16.0.15
stereo_msgs                               : latest=4.9.0, local=4.9.0
ament_cmake_pytest                        : latest=1.3.12, local=1.3.12
topic_monitor                             : latest=0.20.6, local=0.20.5
trajectory_msgs                           : latest=4.9.0, local=4.9.0
ros2node                                  : latest=0.18.14, local=0.18.14
zstd_vendor                               : latest=0.15.15, local=0.15.15
logging_demo                              : latest=0.20.6, local=0.20.5
visualization_msgs                        : latest=4.9.0, local=4.9.0
rosidl_generator_cpp                      : latest=3.1.7, local=3.1.7
ament_index_cpp                           : latest=1.4.0, local=1.4.0
ament_cmake_uncrustify                    : latest=0.12.14, local=0.12.14
rosbag2_transport                         : latest=0.15.15, local=0.15.15
rpyutils                                  : latest=0.2.2, local=0.2.1
rosbag2_storage_default_plugins           : latest=0.15.15, local=0.15.15
ament_cmake_ros                           : latest=0.10.0, local=0.10.0
teleop_twist_keyboard                     : latest=2.4.1, local=2.4.0
uncrustify_vendor                         : latest=2.0.2, local=2.0.2
rosidl_typesupport_fastrtps_cpp           : latest=2.2.3, local=2.2.2
joy                                       : latest=3.3.0, local=3.3.0
turtlesim                                 : latest=1.4.3, local=1.4.2
ros2cli_common_extensions                 : latest=0.1.1, local=0.1.1
rqt_common_plugins                        : latest=1.2.0, local=1.2.0
dummy_robot_bringup                       : latest=0.20.6, local=0.20.5
rosidl_runtime_cpp                        : latest=3.1.7, local=3.1.7
ros2topic                                 : latest=0.18.14, local=0.18.14
pcl_msgs                                  : latest=1.0.0, local=1.0.0
ament_cmake_gen_version_h                 : latest=1.3.12, local=1.3.12
libcurl_vendor                            : latest=3.1.3, local=3.1.3
tf2_sensor_msgs                           : latest=0.25.17, local=0.25.16
ament_cmake_target_dependencies           : latest=1.3.12, local=1.3.12
ament_lint_cmake                          : latest=0.12.14, local=0.12.14
domain_coordinator                        : latest=0.10.0, local=0.10.0
launch_testing_ros                        : latest=0.19.12, local=0.19.12
laser_geometry                            : latest=2.4.1, local=2.4.0
rosidl_typesupport_fastrtps_c             : latest=2.2.3, local=2.2.2
shared_queues_vendor                      : latest=0.15.15, local=0.15.15
launch_xml                                : latest=1.0.12, local=1.0.10
examples_rclpy_minimal_subscriber         : latest=0.15.5, local=0.15.4
action_tutorials_cpp                      : latest=0.20.6, local=0.20.5
rosidl_parser                             : latest=3.1.7, local=3.1.7
ament_cmake_export_include_directories    : latest=1.3.12, local=1.3.12
ament_cmake_lint_cmake                    : latest=0.12.14, local=0.12.14
ament_cmake_core                          : latest=1.3.12, local=1.3.12
tlsf                                      : latest=0.7.0, local=0.7.0
ament_cmake_test                          : latest=1.3.12, local=1.3.12
rqt_py_common                             : latest=1.1.9, local=1.1.7
rqt_shell                                 : latest=1.0.2, local=1.0.2
actionlib_msgs                            : latest=4.9.0, local=4.9.0
examples_rclpy_executors                  : latest=0.15.5, local=0.15.4
composition                               : latest=0.20.6, local=0.20.5
sensor_msgs_py                            : latest=4.9.0, local=4.9.0
rosidl_typesupport_interface              : latest=3.1.7, local=3.1.7
rttest                                    : latest=0.13.0, local=0.13.0
ament_cmake_pep257                        : latest=0.12.14, local=0.12.14
rosbag2_compression                       : latest=0.15.15, local=0.15.15
ament_index_python                        : latest=1.4.0, local=1.4.0
dummy_sensors                             : latest=0.20.6, local=0.20.5
image_transport                           : latest=3.1.12, local=3.1.12
ament_cmake_libraries                     : latest=1.3.12, local=1.3.12
tf2_py                                    : latest=0.25.17, local=0.25.16
unique_identifier_msgs                    : latest=2.2.1, local=2.2.1
rclpy                                     : latest=3.3.18, local=3.3.17
python_cmake_module                       : latest=0.10.0, local=0.10.0
demo_nodes_cpp_native                     : latest=0.20.6, local=0.20.5
examples_rclcpp_minimal_service           : latest=0.15.5, local=0.15.4
rcl_action                                : latest=5.3.11, local=5.3.10
ros2action                                : latest=0.18.14, local=0.18.14
tf2_ros                                   : latest=0.25.17, local=0.25.16
nav_msgs                                  : latest=4.9.0, local=4.9.0
rqt_service_caller                        : latest=1.0.5, local=1.0.5
rclcpp                                    : latest=16.0.15, local=16.0.15
ament_lint                                : latest=0.12.14, local=0.12.14
examples_rclpy_minimal_service            : latest=0.15.5, local=0.15.4
examples_rclpy_minimal_client             : latest=0.15.5, local=0.15.4
ament_cppcheck                            : latest=0.12.14, local=0.12.14
ament_cpplint                             : latest=0.12.14, local=0.12.14
rosgraph_msgs                             : latest=1.2.2, local=1.2.2
rmw                                       : latest=6.1.2, local=6.1.2
ament_flake8                              : latest=0.12.14, local=0.12.14
examples_rclcpp_minimal_action_server     : latest=0.15.5, local=0.15.4
examples_rclcpp_minimal_action_client     : latest=0.15.5, local=0.15.4
sensor_msgs                               : latest=4.9.0, local=4.9.0
urdf_parser_plugin                        : latest=2.6.1, local=2.6.1
rmw_implementation_cmake                  : latest=6.1.2, local=6.1.2
rcpputils                                 : latest=2.4.6, local=2.4.5
sdl2_vendor                               : latest=3.3.0, local=3.3.0
rosidl_typesupport_introspection_c        : latest=3.1.7, local=3.1.7
intra_process_demo                        : latest=0.20.6, local=0.20.5
rclcpp_lifecycle                          : latest=16.0.15, local=16.0.15
rviz_common                               : latest=11.2.22, local=11.2.20
std_srvs                                  : latest=4.9.0, local=4.9.0
ament_cmake_export_targets                : latest=1.3.12, local=1.3.12
tango_icons_vendor                        : latest=0.1.1, local=0.1.1
geometry_msgs                             : latest=4.9.0, local=4.9.0
ament_cmake_export_libraries              : latest=1.3.12, local=1.3.12
rclcpp_action                             : latest=16.0.15, local=16.0.15
rcl                                       : latest=5.3.11, local=5.3.10
rqt_graph                                 : latest=1.3.1, local=1.3.1
ament_package                             : latest=0.14.1, local=0.14.1
examples_rclpy_minimal_action_server      : latest=0.15.5, local=0.15.4
ros2interface                             : latest=0.18.14, local=0.18.14
tracetools                                : latest=4.1.1, local=4.1.1
ament_cmake_cpplint                       : latest=0.12.14, local=0.12.14
ros2cli                                   : latest=0.18.14, local=0.18.14
rviz_rendering                            : latest=11.2.22, local=11.2.20
rcl_logging_spdlog                        : latest=2.3.1, local=2.3.1
ros2lifecycle                             : latest=0.18.14, local=0.18.14
ros2run                                   : latest=0.18.14, local=0.18.14
ament_cmake_gtest                         : latest=1.3.12, local=1.3.12
ament_pep257                              : latest=0.12.14, local=0.12.14
resource_retriever                        : latest=3.1.3, local=3.1.3
rosidl_cli                                : latest=3.1.7, local=3.1.7
demo_nodes_py                             : latest=0.20.6, local=0.20.5
rqt_bag                                   : latest=1.1.5, local=1.1.5
rqt_srv                                   : latest=1.0.3, local=1.0.3
ros2bag                                   : latest=0.15.15, local=0.15.15
ros2param                                 : latest=0.18.14, local=0.18.14
rcl_lifecycle                             : latest=5.3.11, local=5.3.10
examples_rclcpp_minimal_subscriber        : latest=0.15.5, local=0.15.4
ros2service                               : latest=0.18.14, local=0.18.14
tf2_eigen_kdl                             : latest=0.25.17, local=0.25.16
sros2                                     : latest=0.10.7, local=0.10.7
ament_cmake_export_dependencies           : latest=1.3.12, local=1.3.12
rqt_publisher                             : latest=1.5.0, local=1.5.0
example_interfaces                        : latest=0.9.3, local=0.9.3
qt_gui_cpp                                : latest=2.2.4, local=2.2.4
launch_testing_ament_cmake                : latest=1.0.12, local=1.0.10
statistics_msgs                           : latest=1.2.2, local=1.2.2
cv_bridge                                 : latest=3.2.1, local=3.2.1
rqt_console                               : latest=2.0.3, local=2.0.3
console_bridge_vendor                     : latest=1.4.1, local=1.4.1
rosidl_runtime_c                          : latest=3.1.7, local=3.1.7
rqt_gui_cpp                               : latest=1.1.9, local=1.1.7
rqt_gui                                   : latest=1.1.9, local=1.1.7
ros2pkg                                   : latest=0.18.14, local=0.18.14
image_tools                               : latest=0.20.6, local=0.20.5
qt_gui                                    : latest=2.2.4, local=2.2.4
rosidl_default_generators                 : latest=1.2.0, local=1.2.0
action_tutorials_interfaces               : latest=0.20.6, local=0.20.5
demo_nodes_cpp                            : latest=0.20.6, local=0.20.5
ros_workspace                             : latest=1.0.2, local=1.0.2
tf2_geometry_msgs                         : latest=0.25.17, local=0.25.16
ament_lint_auto                           : latest=0.12.14, local=0.12.14
ament_cmake_auto                          : latest=1.3.12, local=1.3.12
vrpn_mocap                                : latest=1.1.0, local=1.1.0
tf2_bullet                                : latest=0.25.17, local=0.25.16
rosbag2_interfaces                        : latest=0.15.15, local=0.15.15
pcl_conversions                           : latest=2.4.5, local=2.4.5
rosidl_runtime_py                         : latest=0.9.3, local=0.9.3
desktop                                   : latest=0.10.0, local=0.10.0
rosidl_generator_c                        : latest=3.1.7, local=3.1.7
rqt_msg                                   : latest=1.2.0, local=1.2.0
sqlite3_vendor                            : latest=0.15.15, local=0.15.15
launch                                    : latest=1.0.12, local=1.0.10
spdlog_vendor                             : latest=1.3.1, local=1.3.1
rviz_ogre_vendor                          : latest=11.2.22, local=11.2.20
examples_rclcpp_minimal_client            : latest=0.15.5, local=0.15.4
rosbag2_cpp                               : latest=0.15.15, local=0.15.15
libyaml_vendor                            : latest=1.2.2, local=1.2.2
rmw_implementation                        : latest=2.8.5, local=2.8.5
rosidl_typesupport_c                      : latest=2.0.2, local=2.0.2
action_tutorials_py                       : latest=0.20.6, local=0.20.5
yaml_cpp_vendor                           : latest=8.0.2, local=8.0.2
dummy_map_server                          : latest=0.20.6, local=0.20.5
ament_cmake_copyright                     : latest=0.12.14, local=0.12.14
common_interfaces                         : latest=4.9.0, local=4.9.0
rqt_gui_py                                : latest=1.1.9, local=1.1.7
examples_rclcpp_minimal_timer             : latest=0.15.5, local=0.15.4
ros_base                                  : latest=0.10.0, local=0.10.0
rosidl_generator_py                       : latest=0.14.6, local=0.14.5
orocos_kdl_vendor                         : latest=0.2.5, local=0.2.5
eigen3_cmake_module                       : latest=0.1.1, local=0.1.1
rqt_topic                                 : latest=1.5.0, local=1.5.0
rviz_default_plugins                      : latest=11.2.22, local=11.2.20
rosidl_default_runtime                    : latest=1.2.0, local=1.2.0
teleop_twist_joy                          : latest=2.4.8, local=2.4.8
ros_core                                  : latest=0.10.0, local=0.10.0
composition_interfaces                    : latest=1.2.2, local=1.2.2
launch_testing                            : latest=1.0.12, local=1.0.10
python_orocos_kdl_vendor                  : latest=0.2.5, local=0.2.5
tf2_ros_py                                : latest=0.25.17, local=0.25.16
qt_gui_py_common                          : latest=2.2.4, local=2.2.4
examples_rclpy_minimal_publisher          : latest=0.15.5, local=0.15.4
tlsf_cpp                                  : latest=0.13.0, local=0.13.0
ament_xmllint                             : latest=0.12.14, local=0.12.14
depthimage_to_laserscan                   : latest=2.5.1, local=2.5.1
shape_msgs                                : latest=4.9.0, local=4.9.0
diagnostic_msgs                           : latest=4.9.0, local=4.9.0
tf2_eigen                                 : latest=0.25.17, local=0.25.16
tinyxml_vendor                            : latest=0.8.3, local=0.8.3
geometry2                                 : latest=0.25.17, local=0.25.16
image_geometry                            : latest=3.2.1, local=3.2.1
rcl_interfaces                            : latest=1.2.2, local=1.2.2
rcl_logging_interface                     : latest=2.3.1, local=2.3.1
ros2doctor                                : latest=0.18.14, local=0.18.14
rosbag2_py                                : latest=0.15.15, local=0.15.15
ament_copyright                           : latest=0.12.14, local=0.12.14
rqt_reconfigure                           : latest=1.1.2, local=1.1.2
rosidl_typesupport_cpp                    : latest=2.0.2, local=2.0.2
ament_cmake                               : latest=1.3.12, local=1.3.12
keyboard_handler                          : latest=0.0.5, local=0.0.5
lifecycle_msgs                            : latest=1.2.2, local=1.2.2
pendulum_control                          : latest=0.20.6, local=0.20.5
rviz2                                     : latest=11.2.22, local=11.2.20
rqt_image_view                            : latest=1.2.0, local=1.2.0
map_msgs                                  : latest=2.1.0, local=2.1.0
urdf                                      : latest=2.6.1, local=2.6.1
ament_cmake_version                       : latest=1.3.12, local=1.3.12
ament_uncrustify                          : latest=0.12.14, local=0.12.14
examples_rclcpp_minimal_publisher         : latest=0.15.5, local=0.15.4
rqt_bag_plugins                           : latest=1.1.5, local=1.1.5
ament_cmake_export_definitions            : latest=1.3.12, local=1.3.12
osrf_pycommon                             : latest=2.1.6, local=2.1.6
rmw_fastrtps_shared_cpp                   : latest=6.2.9, local=6.2.8
ament_lint_common                         : latest=0.12.14, local=0.12.14
libstatistics_collector                   : latest=1.3.4, local=1.3.4
kdl_parser                                : latest=2.6.4, local=2.6.4

   PLATFORM INFORMATION
system           : Linux
platform info    : Linux-6.8.0-85-generic-x86_64-with-glibc2.35
release          : 6.8.0-85-generic
processor        : x86_64

   QOS COMPATIBILITY LIST
compatibility status    : No publisher/subscriber pairs found

   RMW MIDDLEWARE
middleware name    : rmw_fastrtps_cpp

   ROS 2 INFORMATION
distribution name      : humble
distribution type      : ros2
distribution status    : active
release platforms      : {'rhel': ['8'], 'ubuntu': ['jammy']}

   TOPIC LIST
topic               : none
publisher count     : 0
subscriber count    : 0

Steps to reproduce issue

When running a node with a timer callback that is close to or exceeds the timer period, the __del__ method is not called on the node when terminating the process but ONLY when running from sensor_msgs.msg import Imu. When commenting out the message, the __del__ method works as intended.

Reproducible example:

Node:

import rclpy
from rclpy.node import Node

from sensor_msgs.msg import Imu # comment out this line to fix the issue?
import time

class MinimalPublisher(Node):

    def __init__(self):
        super().__init__('minimal_publisher')
        self.get_logger().info('Initialised')
        
        self.timer = self.create_timer(0.1, self.timer_callback)
        
    def __del__(self):
        print("Deleting node")
        
    def timer_callback(self):
        self.get_logger().info('Called!')
        time.sleep(0.09)

def main(args=None):
    rclpy.init(args=args)
    node = MinimalPublisher()
    try:
        rclpy.spin(node)
    except KeyboardInterrupt:
        pass
    node.destroy_node()

if __name__ == '__main__':
    main()

All other files are taken from the minimal publisher example for ros2 humble.

Commenting out the imported line fixes the issue. Other sensor_msgs packages give the same issue (tested with Image and Temperature messages). I have not been able to reproduce the issue with other msg packages (tested with std_msgs.msg.String and nav_msgs.msg.Odometry).

Reducing the time.sleep duration also increases the likelihood of the __del__ method being called.

A coworker and I have also been able to reproduce the issue in a Docker container (base image ros:humble with the package mounted). See the image below, where the first time is without the import, and the second time is with the import:
Image

Expected behavior

__del__ method is called when terminating the process via ctrl-C, printing out "Deleting node"

Actual behavior

__del__ method is not called when the import statement is there, no print statement is made as a result

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions