Skip to content

Commit 963e239

Browse files
Add more notes and TODO comments.
1 parent 9bc6107 commit 963e239

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Python/pystate.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,13 @@ _PyThreadState_Init(PyThreadState *tstate)
12421242
void
12431243
PyThreadState_Clear(PyThreadState *tstate)
12441244
{
1245+
/* XXX Conditions we need to enforce:
1246+
1247+
* the GIL must be held by the current thread
1248+
* current_fast_get()->interp must match tstate->interp
1249+
* for the main interpreter, current_fast_get() must be the main thread
1250+
*/
1251+
12451252
// The GIL must be held by the current thread,
12461253
// which must not be the target.
12471254
// XXX Enforce that (check current_fast_get()).
@@ -1260,6 +1267,17 @@ PyThreadState_Clear(PyThreadState *tstate)
12601267
"PyThreadState_Clear: warning: thread still has a frame\n");
12611268
}
12621269

1270+
/* At this point tstate shouldn't be used any more,
1271+
neither to run Python code nor for other uses.
1272+
1273+
This is tricky when current_fast_get() == tstate, in the same way
1274+
as noted in interpreter_clear() above. The below finalizers
1275+
can possibly run Python code or otherwise use the partially
1276+
cleared thread state. For now we trust that isn't a problem
1277+
in practice.
1278+
*/
1279+
// XXX Deal with the possibility of problematic finalizers.
1280+
12631281
/* Don't clear tstate->pyframe: it is a borrowed reference */
12641282

12651283
Py_CLEAR(tstate->dict);

0 commit comments

Comments
 (0)