Skip to content

Commit

Permalink
Install signal handlers after context is initialized. (#1333) (#1335)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <[email protected]>
Co-authored-by: Shane Loretz <[email protected]>
(cherry picked from commit 53855e3)

Co-authored-by: Tomoya Fujita <[email protected]>
  • Loading branch information
mergify[bot] and fujitatomoya authored Aug 17, 2024
1 parent 95b7da2 commit 6a6e24b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rclpy/rclpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ def init(
"""
context = get_default_context() if context is None else context
if signal_handler_options is None:
if context is None or context is get_default_context():
if context is get_default_context():
signal_handler_options = SignalHandlerOptions.ALL
else:
signal_handler_options = SignalHandlerOptions.NO
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)
return context.init(args, domain_id=domain_id)


# The global spin functions need an executor to do the work
Expand Down

0 comments on commit 6a6e24b

Please sign in to comment.