File tree 3 files changed +12
-6
lines changed
3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -211,7 +211,7 @@ struct _ts {
211
211
* weakref-to-lock (on_delete_data) argument, and release_sentinel releases
212
212
* the indirectly held lock.
213
213
*/
214
- void (* on_delete )(void * );
214
+ int (* on_delete )(void * );
215
215
void * on_delete_data ;
216
216
217
217
int coroutine_origin_tracking_depth ;
Original file line number Diff line number Diff line change @@ -1307,7 +1307,7 @@ yet finished.\n\
1307
1307
This function is meant for internal and specialized purposes only.\n\
1308
1308
In most applications `threading.enumerate()` should be used instead." );
1309
1309
1310
- static void
1310
+ static int
1311
1311
release_sentinel (void * wr_raw )
1312
1312
{
1313
1313
PyObject * wr = _PyObject_CAST (wr_raw );
@@ -1326,6 +1326,7 @@ release_sentinel(void *wr_raw)
1326
1326
/* Deallocating a weakref with a NULL callback only calls
1327
1327
PyObject_GC_Del(), which can't call any Python code. */
1328
1328
Py_DECREF (wr );
1329
+ return 0 ;
1329
1330
}
1330
1331
1331
1332
static PyObject *
Original file line number Diff line number Diff line change @@ -1490,10 +1490,6 @@ PyThreadState_Clear(PyThreadState *tstate)
1490
1490
1491
1491
Py_CLEAR (tstate -> context );
1492
1492
1493
- if (tstate -> on_delete != NULL ) {
1494
- tstate -> on_delete (tstate -> on_delete_data );
1495
- }
1496
-
1497
1493
tstate -> _status .cleared = 1 ;
1498
1494
1499
1495
// XXX Call _PyThreadStateSwap(runtime, NULL) here if "current".
@@ -1565,6 +1561,15 @@ void
1565
1561
_PyThreadState_DeleteCurrent (PyThreadState * tstate )
1566
1562
{
1567
1563
_Py_EnsureTstateNotNULL (tstate );
1564
+ /* We ignore the return value. A non-zero value means there were
1565
+ too many pending calls already queued up. This case is unlikely,
1566
+ and, at worst, we'll leak on_delete_data.
1567
+ Also, note that the pending call will be run the next time the
1568
+ GIL is taken by one of this interpreter's threads. So it won't
1569
+ happen until after the _PyEval_ReleaseLock() call below. */
1570
+ (void )_PyEval_AddPendingCall (tstate -> interp ,
1571
+ tstate -> on_delete , tstate -> on_delete_data );
1572
+
1568
1573
tstate_delete_common (tstate );
1569
1574
current_fast_clear (tstate -> interp -> runtime );
1570
1575
_PyEval_ReleaseLock (tstate );
You can’t perform that action at this time.
0 commit comments