ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Cntl-c/killall gives rcl_shutdown already called only Humble/Jammy

asked 2022-10-22 10:49:41 -0500

RobotDreams gravatar image

updated 2022-10-22 11:01:30 -0500

I have written a basic IMU publisher node (that does not implement lifecycle) which is throwing a "rcl_shutdown already called" error in ROS2 Humble on Jammy (Ubuntu 22.04 Server on Raspberry Pi4) when killed.

It quits cleanly under ROS2 Foxy on Focal (Ubuntu 20.04 Server on Raspberry Pi4).

printenv | grep ROS
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_DOMAIN_ID=0
ROS_LOCALHOST_ONLY=0
ROS_DISTRO=humble

uname -a
Linux ROS2HH 5.15.0-1017-raspi #19-Ubuntu SMP PREEMPT Fri Oct 14 08:22:47 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

Started in foreground and terminated with cntrl-c:

ros2 run ros2_gopigo3_node imu_sensor

Started in background and terminated with killall:

ros2 run ros2_gopigo3_node imu_sensor &
killall imu_sensor

My node:

#!/usr/bin/env python3

# File: imu_sensor.py

# Basic ROS2 Node to publish imu sensor readings
"""
  Publishes:
     /imu/data
     /imu/mag   in units of full Tesla  1 microTesla = 0.000001 Tesla
     /imu/temp
  TODO:
     /imu/status
     /imu/raw
"""

class IMUSensorNode(Node):

    def __init__(self):
        super().__init__('imu_sensor')
        ...

    def timer_callback(self):
        ...


def main(args=None):
    rclpy.init(args=args)

    imu_node = IMUSensorNode()

    try:
      rclpy.spin(imu_node)
    except KeyboardInterrupt:
      print('\ncontrol-c: imu_sensor node shutting down')
    finally:
      imu_node.destroy_node()
      rclpy.shutdown()

Note: it throws the same error on exit without the try-except-finally construct also:

def main(args=None):
    rclpy.init(args=args)

    imu_node = IMUSensorNode()

    rclpy.spin(imu_node)
    imu_node.destroy_node()
    rclpy.shutdown()

This is the full error:

$ ros2 run ros2_gopigo3_node imu_sensor 
[INFO] [1666452685.296127347] [imu_sensor]: Created imu_sensor node at 30 hz
^C
control-c: imu_sensor node shutting down
Traceback (most recent call last):
  File "/home/ubuntu/ros2ws/install/ros2_gopigo3_node/lib/ros2_gopigo3_node/imu_sensor", line 33, in <module>
    sys.exit(load_entry_point('ros2-gopigo3-node==0.0.0', 'console_scripts', 'imu_sensor')())
  File "/home/ubuntu/ros2ws/install/ros2_gopigo3_node/lib/python3.10/site-packages/ros2_gopigo3_node/imu_sensor.py", line 121, in main
    rclpy.shutdown()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/__init__.py", line 126, in shutdown
    _shutdown(context=context)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/utilities.py", line 58, in shutdown
    return context.shutdown()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/context.py", line 102, in shutdown
    self.__context.shutdown()
rclpy._rclpy_pybind11.RCLError: failed to shutdown: rcl_shutdown already called on the given context, at ./src/rcl/init.c:241
[ros2run]: Process exited with failure 1
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-02-03 22:48:10 -0500

Daniel Stonier gravatar image
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-10-22 10:49:41 -0500

Seen: 564 times

Last updated: Feb 03 '23