File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -2755,3 +2755,42 @@ def fd_count():
2755
2755
msvcrt .CrtSetReportMode (report_type , old_modes [report_type ])
2756
2756
2757
2757
return count
2758
+
2759
+
2760
+ class SaveSignals :
2761
+ """
2762
+ Save an restore signal handlers.
2763
+
2764
+ This class is only able to save/restore signal handlers registered
2765
+ by the Python signal module: see bpo-13285 for "external" signal
2766
+ handlers.
2767
+ """
2768
+
2769
+ def __init__ (self ):
2770
+ import signal
2771
+ self .signal = signal
2772
+ self .signals = list (range (1 , signal .NSIG ))
2773
+ # SIGKILL and SIGSTOP signals cannot be ignored nor catched
2774
+ for signame in ('SIGKILL' , 'SIGSTOP' ):
2775
+ try :
2776
+ signum = getattr (signal , signame )
2777
+ except AttributeError :
2778
+ continue
2779
+ self .signals .remove (signum )
2780
+ self .handlers = {}
2781
+
2782
+ def save (self ):
2783
+ for signum in self .signals :
2784
+ handler = self .signal .getsignal (signum )
2785
+ if handler is None :
2786
+ # getsignal() returns None if a signal handler was not
2787
+ # registered by the Python signal module,
2788
+ # and the handler is not SIG_DFL nor SIG_IGN.
2789
+ #
2790
+ # Ignore the signal: we cannot restore the handler.
2791
+ continue
2792
+ self .handlers [signum ] = handler
2793
+
2794
+ def restore (self ):
2795
+ for signum , handler in self .handlers .items ():
2796
+ self .signal .signal (signum , handler )
Original file line number Diff line number Diff line change 15
15
import tempfile
16
16
import unittest
17
17
18
- from test .support import requires , import_module , verbose
18
+ from test .support import requires , import_module , verbose , SaveSignals
19
19
20
20
# Optionally test curses module. This currently requires that the
21
21
# 'curses' resource be given on the regrtest command line using the -u
@@ -63,6 +63,8 @@ def tearDownClass(cls):
63
63
del cls .t
884C
mp
64
64
65
65
def setUp (self ):
66
+ self .save_signals = SaveSignals ()
67
+ self .save_signals .save ()
66
68
if verbose :
67
69
# just to make the test output a little more readable
68
70
print ()
@@ -72,6 +74,7 @@ def setUp(self):
72
74
def tearDown (self ):
73
75
curses .resetty ()
74
76
curses .endwin ()
77
+ self .save_signals .restore ()
75
78
76
79
def test_window_funcs (self ):
77
80
"Test the methods of windows"
You can’t perform that action at this time.
0 commit comments