@@ -1539,27 +1539,32 @@ create_localsdict(localobject *self, thread_module_state *state,
1539
1539
goto err ;
1540
1540
}
1541
1541
1542
- if (PyDict_SetItem (self -> localdicts , tstate -> threading_local_key , ldict ) <
1543
- 0 ) {
1542
+ if (PyDict_SetItem (self -> localdicts , tstate -> threading_local_key ,
1543
+ ldict ) < 0 )
1544
+ {
1544
1545
goto err ;
1545
1546
}
1546
1547
1547
1548
wr = create_sentinel_wr (self );
1548
1549
if (wr == NULL ) {
1549
1550
PyObject * exc = PyErr_GetRaisedException ();
1550
- if (PyDict_DelItem (self -> localdicts , tstate -> threading_local_key ) <
1551
- 0 ) {
1552
- PyErr_WriteUnraisable ((PyObject * )self );
1551
+ if (PyDict_DelItem (self -> localdicts ,
1552
+ tstate -> threading_local_key ) < 0 )
1553
+ {
1554
+ PyErr_FormatUnraisable ("Exception ignored while deleting "
1555
+ "thread local of %R" , self );
1553
1556
}
1554
1557
PyErr_SetRaisedException (exc );
1555
1558
goto err ;
1556
1559
}
1557
1560
1558
1561
if (PySet_Add (self -> thread_watchdogs , wr ) < 0 ) {
1559
1562
PyObject * exc = PyErr_GetRaisedException ();
1560
- if (PyDict_DelItem (self -> localdicts , tstate -> threading_local_key ) <
1561
- 0 ) {
1562
- PyErr_WriteUnraisable ((PyObject * )self );
1563
+ if (PyDict_DelItem (self -> localdicts ,
1564
+ tstate -> threading_local_key ) < 0 )
1565
+ {
1566
+ PyErr_FormatUnraisable ("Exception ignored while deleting "
1567
+ "thread local of %R" , self );
1563
1568
}
1564
1569
PyErr_SetRaisedException (exc );
1565
1570
goto err ;
@@ -1609,13 +1614,16 @@ _ldict(localobject *self, thread_module_state *state)
1609
1614
we create a new one the next time we do an attr
1610
1615
access */
1611
1616
PyObject * exc = PyErr_GetRaisedException ();
1612
- if (PyDict_DelItem (self -> localdicts , tstate -> threading_local_key ) <
1613
- 0 ) {
1614
- PyErr_WriteUnraisable ((PyObject * )self );
1615
- PyErr_Clear ();
1617
+ if (PyDict_DelItem (self -> localdicts ,
1618
+ tstate -> threading_local_key ) < 0 )
1619
+ {
1620
+ PyErr_FormatUnraisable ("Exception ignored while deleting "
1621
+ "thread local of %R" , self );
1622
+ assert (!PyErr_Occurred ());
1616
1623
}
1617
1624
if (PySet_Discard (self -> thread_watchdogs , wr ) < 0 ) {
1618
- PyErr_WriteUnraisable ((PyObject * )self );
1625
+ PyErr_FormatUnraisable ("Exception ignored while discarding "
1626
+ "thread watchdog of %R" , self );
1619
1627
}
1620
1628
PyErr_SetRaisedException (exc );
1621
1629
Py_DECREF (ldict );
@@ -1746,12 +1754,14 @@ clear_locals(PyObject *locals_and_key, PyObject *dummyweakref)
1746
1754
if (self -> localdicts != NULL ) {
1747
1755
PyObject * key = PyTuple_GetItem (locals_and_key , 1 );
1748
1756
if (PyDict_Pop (self -> localdicts , key , NULL ) < 0 ) {
1749
- PyErr_WriteUnraisable ((PyObject * )self );
1757
+ PyErr_FormatUnraisable ("Exception ignored while clearing "
1758
+ "thread local %R" , (PyObject * )self );
1750
1759
}
1751
1760
}
1752
1761
if (self -> thread_watchdogs != NULL ) {
1753
1762
if (PySet_Discard (self -> thread_watchdogs , dummyweakref ) < 0 ) {
1754
- PyErr_WriteUnraisable ((PyObject * )self );
1763
+ PyErr_FormatUnraisable ("Exception ignored while clearing "
1764
+ "thread local %R" , (PyObject * )self );
1755
1765
}
1756
1766
}
1757
1767
@@ -2314,7 +2324,8 @@ thread_shutdown(PyObject *self, PyObject *args)
2314
2324
// Wait for the thread to finish. If we're interrupted, such
2315
2325
// as by a ctrl-c we print the error and exit early.
2316
2326
if (ThreadHandle_join (handle , -1 ) < 0 ) {
2317
- PyErr_WriteUnraisable (NULL );
2327
+ PyErr_FormatUnraisable ("Exception ignored while joining a thread "
2328
+ "in _thread._shutdown()" );
2318
2329
ThreadHandle_decref (handle );
2319
2330
Py_RETURN_NONE ;
2320
2331
}
0 commit comments