@@ -115,7 +115,7 @@ def parse_args_advanced(args):
115115 "-u" ,
116116 "--unload-on-kill" ,
117117 action = "store_true" ,
118- help = "Deactivate the active controllers and unload them on kill " ,
118+ help = "Deactivate the active controllers and unload them on SIGINT or SIGTERM " ,
119119 )
120120 global_parser .add_argument ("-h" , "--help" , action = "store_true" , help = "Show help" )
121121
@@ -253,7 +253,7 @@ def parse_native_args(args):
253253 parser .add_argument (
254254 "-u" ,
255255 "--unload-on-kill" ,
256- help = "Wait until this application is interrupted and unload controller " ,
256+ help = "Wait until this application is interrupted (SIGINT or SIGTERM) and deactivate/ unload controllers " ,
257257 action = "store_true" ,
258258 )
259259 parser .add_argument (
@@ -372,6 +372,13 @@ def get_ros_params_files(argv):
372372 activate_as_group = global_args .activate_as_group
373373 unload_on_kill = global_args .unload_on_kill
374374 node = None
375+ lock = None
376+
377+ def _on_shutdown_signal (signum , frame ):
378+ raise KeyboardInterrupt ()
379+
380+ signal .signal (signal .SIGINT , _on_shutdown_signal )
381+ signal .signal (signal .SIGTERM , _on_shutdown_signal )
375382
376383 if spawner_ros_params_files :
377384 for controller in controllers :
@@ -604,6 +611,7 @@ def get_ros_params_files(argv):
604611 # second KeyboardInterrupt during the signal.signal() call itself.
605612 try :
606613 signal .signal (signal .SIGINT , signal .SIG_IGN )
614+ signal .signal (signal .SIGTERM , signal .SIG_IGN )
607615 except (KeyboardInterrupt , Exception ):
608616 pass
609617 if unload_on_kill :
@@ -662,7 +670,7 @@ def get_ros_params_files(argv):
662670 finally :
663671 if node :
664672 node .destroy_node ()
665- if lock .is_locked :
673+ if lock is not None and lock .is_locked :
666674 lock .release ()
667675 rclpy .shutdown ()
668676
0 commit comments