Commit e09f33e
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`.
(cherry picked from commit 90fe325)
Co-authored-by: Sam Gross <colesbury@gmail.com>
1 parent db8b943 commit e09f33e
File tree
4 files changed
+51
-4
lines changed- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Python
4 files changed
+51
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1381 | 1381 | | |
1382 | 1382 | | |
1383 | 1383 | | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
1384 | 1411 | | |
1385 | 1412 | | |
1386 | 1413 | | |
| |||
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 | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
345 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
346 | 358 | | |
347 | 359 | | |
348 | 360 | | |
| |||
354 | 366 | | |
355 | 367 | | |
356 | 368 | | |
357 | | - | |
| 369 | + | |
358 | 370 | | |
359 | 371 | | |
360 | 372 | | |
| |||
366 | 378 | | |
367 | 379 | | |
368 | 380 | | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
369 | 384 | | |
370 | 385 | | |
371 | 386 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2345 | 2345 | | |
2346 | 2346 | | |
2347 | 2347 | | |
2348 | | - | |
| 2348 | + | |
| 2349 | + | |
2349 | 2350 | | |
2350 | 2351 | | |
2351 | 2352 | | |
2352 | 2353 | | |
2353 | 2354 | | |
2354 | 2355 | | |
| 2356 | + | |
2355 | 2357 | | |
2356 | 2358 | | |
2357 | 2359 | | |
| |||
2417 | 2419 | | |
2418 | 2420 | | |
2419 | 2421 | | |
| 2422 | + | |
2420 | 2423 | | |
2421 | 2424 | | |
2422 | 2425 | | |
2423 | 2426 | | |
2424 | 2427 | | |
2425 | 2428 | | |
2426 | | - | |
2427 | 2429 | | |
2428 | 2430 | | |
2429 | 2431 | | |
| |||
0 commit comments