From aacf8f0f66167e0d77729a8c5314a73b4ef5d07f Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Wed, 7 Aug 2024 13:19:07 -0700 Subject: [PATCH] Initialize signal handlers after context (#1331) Signed-off-by: Shane Loretz --- rclpy/rclpy/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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