From 9da7430675ceaeae5abeb9c9f7cd552b71b3a93a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 20 Nov 2019 11:17:17 +0100 Subject: bpo-36854: Clear the current thread later (GH-17279) Clear the current thread later in the Python finalization. * The PyInterpreterState_Delete() function is now responsible to call PyThreadState_Swap(NULL). * The tstate_delete_common() function is now responsible to clear the "autoTSSKey" thread local storage and it only clears it once the thread state is fully cleared. It allows to still get the current thread from TSS in tstate_delete_common(). --- Python/pylifecycle.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 2975b3ebd6..73114df79c 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1226,9 +1226,6 @@ finalize_interp_delete(PyThreadState *tstate, int is_main_interp) _PyGILState_Fini(tstate); } - /* Delete current thread. After this, many C API calls become crashy. */ - PyThreadState_Swap(NULL); - PyInterpreterState_Delete(tstate->interp); } @@ -1577,9 +1574,9 @@ handle_error: PyErr_PrintEx(0); PyThreadState_Clear(tstate); - PyThreadState_Swap(save_tstate); PyThreadState_Delete(tstate); PyInterpreterState_Delete(interp); + PyThreadState_Swap(save_tstate); *tstate_p = NULL; return _PyStatus_OK(); -- cgit v1.2.1