Commit 90fe325
authored
There was a deadlock originally seen by Memray when a daemon thread
enabled or disabled profiling while the interpreter was shutting down.
I think this could also happen with garbage collection, but I haven't
seen that in practice.
The daemon thread could be hung while trying acquire the global rwmutex
that prevents overlapping global and per-interpreter stop-the-world events.
Since it already held the main interpreter's stop-the-world lock, it
also deadlocked the main thread, which is trying to perform interpreter
finalization.
Swap the order of lock acquisition to prevent this deadlock.
Additionally, refactor `_PyParkingLot_Park` so that the global buckets
hashtable is left in a clean state if the thread is hung in
`PyEval_AcquireThread`.
1 parent 4c0d7bc commit 90fe325
File tree
6 files changed
+55
-31
lines changed- Include/internal
- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Python
6 files changed
+55
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | 49 | | |
52 | | - | |
| 50 | + | |
53 | 51 | | |
54 | 52 | | |
55 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1430 | 1430 | | |
1431 | 1431 | | |
1432 | 1432 | | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
1433 | 1460 | | |
1434 | 1461 | | |
1435 | 1462 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
| 230 | + | |
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | | - | |
| 94 | + | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | 228 | | |
250 | 229 | | |
251 | 230 | | |
| |||
342 | 321 | | |
343 | 322 | | |
344 | 323 | | |
345 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
346 | 337 | | |
347 | 338 | | |
348 | 339 | | |
| |||
354 | 345 | | |
355 | 346 | | |
356 | 347 | | |
357 | | - | |
| 348 | + | |
358 | 349 | | |
359 | 350 | | |
360 | 351 | | |
| |||
366 | 357 | | |
367 | 358 | | |
368 | 359 | | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
369 | 363 | | |
370 | 364 | | |
371 | 365 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2253 | 2253 | | |
2254 | 2254 | | |
2255 | 2255 | | |
2256 | | - | |
| 2256 | + | |
| 2257 | + | |
2257 | 2258 | | |
2258 | 2259 | | |
2259 | 2260 | | |
2260 | 2261 | | |
2261 | 2262 | | |
2262 | 2263 | | |
| 2264 | + | |
2263 | 2265 | | |
2264 | 2266 | | |
2265 | 2267 | | |
| |||
2325 | 2327 | | |
2326 | 2328 | | |
2327 | 2329 | | |
| 2330 | + | |
2328 | 2331 | | |
2329 | 2332 | | |
2330 | 2333 | | |
2331 | 2334 | | |
2332 | 2335 | | |
2333 | 2336 | | |
2334 | | - | |
2335 | 2337 | | |
2336 | 2338 | | |
2337 | 2339 | | |
| |||
0 commit comments