Skip to content

Cannot shutdown context from callbacks #1489

@fennel-labs

Description

@fennel-labs

Generated by Generative AI

No response

Operating System:

Docker: ros:humble-perception-jammy (Ubuntu 22)

ROS version or commit hash:

Docker: ros:humble-perception-jammy (Humble)

RMW implementation (if applicable):

No response

RMW Configuration (if applicable):

No response

Client library (if applicable):

rclpy

'ros2 doctor --report' output

Steps to reproduce issue

Execute the following node code:

import rclpy
from rclpy.node import Node

class ShutdownTimerNode(Node):
    def __init__(self):
        super().__init__('shutdown_timer_node')
        self.create_timer(2.0, self.timer_callback)

    def timer_callback(self):
        self.get_logger().info('Timer triggered, shutting down...')
        rclpy.shutdown()

def main(args=None):
    rclpy.init(args=args)
    node = ShutdownTimerNode()
    try:
        node.get_logger().info('Node is running, waiting for timer...')
        rclpy.spin(node)
    except KeyboardInterrupt:
        node.get_logger().info('Keyboard interrupt received, shutting down...')

if __name__ == '__main__':
    main()

Expected behavior

According to the documentation , rclpy.shutdown() shuts down the node context including the executor. rclpy.spin() blocks until the executor is shut down. Thus, calling rclpy.shutdown() from the timer callback should cause the node to terminate.

Actual behavior

The node does not terminate. This means either the rclpy has a bug or the documentation is incorrect. If the documentation is incorrect, I would like to learn about the intended way to shutdown a ROS node without using sys.exit().

Additional information

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions