diff --git a/rclpy/rclpy/__init__.py b/rclpy/rclpy/__init__.py index f57b14a65..9c43deb0a 100644 --- a/rclpy/rclpy/__init__.py +++ b/rclpy/rclpy/__init__.py @@ -88,8 +88,12 @@ def __init__(self, self.installed_signal_handlers = False else: self.installed_signal_handlers = True - install_signal_handlers(signal_handler_options) self.context.init(args, domain_id=domain_id) + # Install signal handlers after initializing the context because the rclpy signal + # handler only does something if there is at least one initialized context. + # It is desirable for sigint or sigterm to be able to terminate the process if rcl_init + # takes a long time, and the default signal handlers work well for that purpose. + install_signal_handlers(signal_handler_options) def __enter__(self) -> 'InitContextManager': return self