From 7c7f4ec91a183b9ac40d4b856d563141146a8249 Mon Sep 17 00:00:00 2001 From: Gabriele Tornetta Date: Sat, 31 Dec 2022 23:32:29 +0000 Subject: [PATCH] Update native_thread_id after fork --- .../2022-12-31-23-32-09.gh-issue-100649.C0fY4S.rst | 1 + Modules/posixmodule.c | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-12-31-23-32-09.gh-issue-100649.C0fY4S.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-31-23-32-09.gh-issue-100649.C0fY4S.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-31-23-32-09.gh-issue-100649.C0fY4S.rst new file mode 100644 index 000000000000000..7ee929ad09fb5a8 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-12-31-23-32-09.gh-issue-100649.C0fY4S.rst @@ -0,0 +1 @@ +Update the native_thread_id field of PyThreadState after fork. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 1d9a33ab7bc9098..0d4c179368ceac1 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -595,6 +595,10 @@ PyOS_AfterFork_Child(void) PyThreadState *tstate = _PyThreadState_GET(); _Py_EnsureTstateNotNULL(tstate); +#ifdef PY_HAVE_THREAD_NATIVE_ID + tstate->native_thread_id = PyThread_get_thread_native_id(); +#endif + status = _PyEval_ReInitThreads(tstate); if (_PyStatus_EXCEPTION(status)) { goto fatal_error;