@@ -489,24 +489,31 @@ def setup(app):
489
489
import binascii
490
490
paramiko .client .hexlify = lambda x : binascii .hexlify (x ).decode ()
491
491
paramiko .util .safe_string = lambda x : '' # function result never *actually used*
492
- class EndlessLoop (BaseException ): pass
493
- def sigabrt_handler (signum , frame ):
494
- raise EndlessLoop ()
495
- # thread.interrupt_main received the signum parameter in Python 3.10
496
- if sys .version_info >= (3 , 10 ):
497
- signal .signal (signal .SIGABRT , sigabrt_handler )
498
- def alrm_handler ():
499
- try :
500
- import thread
501
- except ImportError :
502
- import _thread as thread
503
- # pre Python 3.10 this raises a KeyboardInterrupt in the main thread.
504
- # it might not show a traceback in that case, but it will stop the endless loop.
505
- thread .interrupt_main (signal .SIGABRT )
506
- timer = threading .Timer (interval = 180 , function = alrm_handler ) # three minutes
492
+ class EndlessLoop (Exception ): pass
493
+ if hasattr (signal , 'alarm' ):
494
+ def alrm_handler (sig , frame ):
495
+ signal .alarm (180 ) # three minutes
496
+ raise EndlessLoop ()
497
+ signal .signal (signal .SIGALRM , alrm_handler )
498
+ signal .alarm (600 ) # ten minutes
499
+ else :
500
+ def sigabrt_handler (signum , frame ):
501
+ raise EndlessLoop ()
502
+ # thread.interrupt_main received the signum parameter in Python 3.10
503
+ if sys .version_info >= (3 , 10 ):
504
+ signal .signal (signal .SIGABRT , sigabrt_handler )
505
+ def alrm_handler ():
506
+ try :
507
+ import thread
508
+ except ImportError :
509
+ import _thread as thread
510
+ # pre Python 3.10 this raises a KeyboardInterrupt in the main thread.
511
+ # it might not show a traceback in that case, but it will stop the endless loop.
512
+ thread .interrupt_main (signal .SIGABRT )
513
+ timer = threading .Timer (interval = 180 , function = alrm_handler ) # three minutes
514
+ timer .daemon = True
515
+ timer .start ()
516
+ import threading
517
+ timer = threading .Timer (interval = 600 , function = alrm_handler ) # ten minutes
507
518
timer .daemon = True
508
519
timer .start ()
509
- import threading
510
- timer = threading .Timer (interval = 600 , function = alrm_handler ) # ten minutes
511
- timer .daemon = True
512
- timer .start ()
0 commit comments