Commit 304b72b
committed
fix: enable graceful Windows process shutdown with CTRL_C_EVENT
Fixes the issue where cleanup code after `yield` in lifespan context
managers was not executed on Windows. The problem occurred because
`process.terminate()` forcefully killed processes without allowing
cleanup code to run.
This change modifies the Windows process termination to:
1. First attempt graceful shutdown using `signal.CTRL_C_EVENT`
2. Wait up to 2 seconds for the process to exit gracefully
3. Fall back to `terminate()` if graceful shutdown fails
4. Finally use `kill()` as a last resort
The fix applies to both `FallbackProcess.__aexit__` and
`terminate_windows_process()` functions, ensuring that Windows
processes can perform proper cleanup operations before exiting.
Reported-by: ScatterTemple
Github-Issue: #10271 parent 4b65963 commit 304b72b
1 file changed
+47
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
79 | | - | |
80 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
81 | 104 | | |
82 | 105 | | |
83 | 106 | | |
| |||
163 | 186 | | |
164 | 187 | | |
165 | 188 | | |
166 | | - | |
| 189 | + | |
167 | 190 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
172 | 194 | | |
173 | 195 | | |
174 | 196 | | |
175 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
176 | 211 | | |
177 | 212 | | |
178 | 213 | | |
179 | 214 | | |
180 | 215 | | |
181 | 216 | | |
182 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
0 commit comments