@@ -1539,27 +1539,32 @@ create_localsdict(localobject *self, thread_module_state *state,
15391539 goto err ;
15401540 }
15411541
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+ {
15441545 goto err ;
15451546 }
15461547
15471548 wr = create_sentinel_wr (self );
15481549 if (wr == NULL ) {
15491550 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 );
15531556 }
15541557 PyErr_SetRaisedException (exc );
15551558 goto err ;
15561559 }
15571560
15581561 if (PySet_Add (self -> thread_watchdogs , wr ) < 0 ) {
15591562 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 );
15631568 }
15641569 PyErr_SetRaisedException (exc );
15651570 goto err ;
@@ -1609,13 +1614,16 @@ _ldict(localobject *self, thread_module_state *state)
16091614 we create a new one the next time we do an attr
16101615 access */
16111616 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 ());
16161623 }
16171624 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 );
16191627 }
16201628 PyErr_SetRaisedException (exc );
16211629 Py_DECREF (ldict );
@@ -1746,12 +1754,14 @@ clear_locals(PyObject *locals_and_key, PyObject *dummyweakref)
17461754 if (self -> localdicts != NULL ) {
17471755 PyObject * key = PyTuple_GetItem (locals_and_key , 1 );
17481756 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 );
17501759 }
17511760 }
17521761 if (self -> thread_watchdogs != NULL ) {
17531762 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 );
17551765 }
17561766 }
17571767
@@ -2314,7 +2324,8 @@ thread_shutdown(PyObject *self, PyObject *args)
23142324 // Wait for the thread to finish. If we're interrupted, such
23152325 // as by a ctrl-c we print the error and exit early.
23162326 if (ThreadHandle_join (handle , -1 ) < 0 ) {
2317- PyErr_WriteUnraisable (NULL );
2327+ PyErr_FormatUnraisable ("Exception ignored while joining a thread "
2328+ "in _thread._shutdown()" );
23182329 ThreadHandle_decref (handle );
23192330 Py_RETURN_NONE ;
23202331 }
0 commit comments