From cde283d16d87024f455e45c6f1b4e4f7d8905836 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 24 Jun 2020 03:21:15 +0200 Subject: [PATCH] bpo-40521: Fix _PyContext_Fini() (GH-21103) Only clear _token_missing in the main interpreter. --- Python/context.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python/context.c b/Python/context.c index dc340718847..15d8b8ea4b9 100644 --- a/Python/context.c +++ b/Python/context.c @@ -1302,7 +1302,9 @@ _PyContext_ClearFreeList(PyThreadState *tstate) void _PyContext_Fini(PyThreadState *tstate) { - Py_CLEAR(_token_missing); + if (_Py_IsMainInterpreter(tstate)) { + Py_CLEAR(_token_missing); + } _PyContext_ClearFreeList(tstate); #ifdef Py_DEBUG struct _Py_context_state *state = &tstate->interp->context;