@@ -780,7 +780,7 @@ def unregister_command_set(self, cmdset: CommandSet) -> None:
780
780
781
781
methods = inspect .getmembers (
782
782
cmdset ,
783
- predicate = lambda meth : isinstance (meth , Callable ) # type: ignore[arg-type]
783
+ predicate = lambda meth : isinstance (meth , Callable ) # type: ignore[arg-type, var-annotated ]
784
784
and hasattr (meth , '__name__' )
785
785
and meth .__name__ .startswith (COMMAND_FUNC_PREFIX ),
786
786
)
@@ -811,7 +811,7 @@ def unregister_command_set(self, cmdset: CommandSet) -> None:
811
811
def _check_uninstallable (self , cmdset : CommandSet ) -> None :
812
812
methods = inspect .getmembers (
813
813
cmdset ,
814
- predicate = lambda meth : isinstance (meth , Callable ) # type: ignore[arg-type]
814
+ predicate = lambda meth : isinstance (meth , Callable ) # type: ignore[arg-type, var-annotated ]
815
815
and hasattr (meth , '__name__' )
816
816
and meth .__name__ .startswith (COMMAND_FUNC_PREFIX ),
817
817
)
@@ -2418,7 +2418,7 @@ def get_help_topics(self) -> List[str]:
2418
2418
def sigint_handler (self , signum : int , _ : FrameType ) -> None :
2419
2419
"""Signal handler for SIGINTs which typically come from Ctrl-C events.
2420
2420
2421
- If you need custom SIGINT behavior, then override this function .
2421
+ If you need custom SIGINT behavior, then override this method .
2422
2422
2423
2423
:param signum: signal number
2424
2424
:param _: required param for signal handlers
@@ -2437,6 +2437,30 @@ def sigint_handler(self, signum: int, _: FrameType) -> None:
2437
2437
if raise_interrupt :
2438
2438
self ._raise_keyboard_interrupt ()
2439
2439
2440
+ def sigterm_handler (self , signum : int , _ : FrameType ) -> None :
2441
+ """
2442
+ Signal handler for SIGTERMs which are sent to politely ask this app to terminate.
2443
+
2444
+ If you need custom SIGTERM behavior, then override this method.
2445
+
2446
+ :param signum: signal number
2447
+ :param _: required param for signal handlers
2448
+ """
2449
+ # Gracefully exit so the persistent history file will be written.
2450
+ sys .exit (self .exit_code )
2451
+
2452
+ def sighup_handler (self , signum : int , _ : FrameType ) -> None :
2453
+ """
2454
+ Signal handler for SIGHUPs which are sent when the terminal is closed.
2455
+
2456
+ If you need custom SIGHUP behavior, then override this method.
2457
+
2458
+ :param signum: signal number
2459
+ :param _: required param for signal handlers
2460
+ """
2461
+ # Gracefully exit so the persistent history file will be written.
2462
+ sys .exit (self .exit_code )
2463
+
2440
2464
def _raise_keyboard_interrupt (self ) -> None :
2441
2465
"""Helper function to raise a KeyboardInterrupt"""
2442
2466
raise KeyboardInterrupt ("Got a keyboard interrupt" )
@@ -5447,6 +5471,12 @@ def cmdloop(self, intro: Optional[str] = None) -> int: # type: ignore[override]
5447
5471
original_sigint_handler = signal .getsignal (signal .SIGINT )
5448
5472
signal .signal (signal .SIGINT , self .sigint_handler ) # type: ignore
5449
5473
5474
+ original_sigterm_handler = signal .getsignal (signal .SIGTERM )
5475
+ signal .signal (signal .SIGTERM , self .sigterm_handler ) # type: ignore
5476
+
5477
+ original_sighup_handler = signal .getsignal (signal .SIGHUP )
5478
+ signal .signal (signal .SIGHUP , self .sighup_handler ) # type: ignore
5479
+
5450
5480
# Grab terminal lock before the command line prompt has been drawn by readline
5451
5481
self .terminal_lock .acquire ()
5452
5482
@@ -5479,8 +5509,10 @@ def cmdloop(self, intro: Optional[str] = None) -> int: # type: ignore[override]
5479
5509
# This will also zero the lock count in case cmdloop() is called again
5480
5510
self .terminal_lock .release ()
5481
5511
5482
- # Restore the original signal handler
5512
+ # Restore the original signal handlers
5483
5513
signal .signal (signal .SIGINT , original_sigint_handler )
5514
+ signal .signal (signal .SIGTERM , original_sigterm_handler )
5515
+ signal .signal (signal .SIGHUP , original_sighup_handler )
5484
5516
5485
5517
return self .exit_code
5486
5518
0 commit comments