Commit 50ac0c0
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 <[email protected]>
1 parent dc4d016 commit 50ac0c0
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 | |
|---|---|---|---|
| |||
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 | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| |||
| 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 | |
|---|---|---|---|
| |||
2364 | 2364 | | |
2365 | 2365 | | |
2366 | 2366 | | |
2367 | | - | |
| 2367 | + | |
| 2368 | + | |
2368 | 2369 | | |
2369 | 2370 | | |
2370 | 2371 | | |
2371 | 2372 | | |
2372 | 2373 | | |
2373 | 2374 | | |
| 2375 | + | |
2374 | 2376 | | |
2375 | 2377 | | |
2376 | 2378 | | |
| |||
2436 | 2438 | | |
2437 | 2439 | | |
2438 | 2440 | | |
| 2441 | + | |
2439 | 2442 | | |
2440 | 2443 | | |
2441 | 2444 | | |
2442 | 2445 | | |
2443 | 2446 | | |
2444 | 2447 | | |
2445 | | - | |
2446 | 2448 | | |
2447 | 2449 | | |
2448 | 2450 | | |
| |||
0 commit comments