Commit 9680dcf
fix: add SIGINT signal handler for reliable Ctrl+C experiment abort (#1504)
* fix: add SIGINT signal handler for reliable Ctrl+C experiment abort
sys.excepthook alone cannot reliably catch KeyboardInterrupt when the
main thread is blocked in C extensions (NumPy/PyTorch). Register a
signal.SIGINT handler as an additional safety net to ensure experiments
are always marked as "aborted" on Ctrl+C.
Fixes #1329
* fix: correct SIGINT handler chaining for SIG_IGN case
When the original handler was SIG_IGN, the handler incorrectly raised
KeyboardInterrupt instead of silently returning. Simplify the logic to
explicitly handle SIG_IGN, callable handlers, and SIG_DFL separately.
Add test for SIG_IGN scenario.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Call saved original excepthook and update tests
Invoke the saved original excepthook (self._sys_origin_excepthook) instead of directly calling sys.__excepthook__, and make the KeyboardInterrupt log message clearer ("aborting run..."). Update unit tests to set and assert against the saved hook, rename tests for clarity, and add coverage to ensure an outer framework's hook is used (and the builtin is not called) as well as that internal errors still result in calling the saved hook.
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Kang Li <79990647+SAKURA-CAT@users.noreply.github.com>1 parent 8ef2a43 commit 9680dcf
2 files changed
Lines changed: 99 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
148 | 153 | | |
149 | 154 | | |
150 | 155 | | |
| |||
153 | 158 | | |
154 | 159 | | |
155 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
156 | 181 | | |
157 | 182 | | |
158 | 183 | | |
| |||
172 | 197 | | |
173 | 198 | | |
174 | 199 | | |
175 | | - | |
| 200 | + | |
176 | 201 | | |
177 | 202 | | |
178 | 203 | | |
| |||
181 | 206 | | |
182 | 207 | | |
183 | 208 | | |
184 | | - | |
| 209 | + | |
185 | 210 | | |
186 | 211 | | |
187 | 212 | | |
| |||
191 | 216 | | |
192 | 217 | | |
193 | 218 | | |
| 219 | + | |
194 | 220 | | |
195 | 221 | | |
196 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| |||
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
60 | | - | |
61 | | - | |
62 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
70 | | - | |
71 | | - | |
72 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
73 | 76 | | |
74 | 77 | | |
75 | | - | |
76 | | - | |
| 78 | + | |
| 79 | + | |
77 | 80 | | |
78 | | - | |
79 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
80 | 94 | | |
81 | | - | |
| 95 | + | |
| 96 | + | |
82 | 97 | | |
83 | 98 | | |
84 | | - | |
| 99 | + | |
85 | 100 | | |
86 | 101 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
0 commit comments