From: Serhiy Storchaka Date: Mon, 20 Jul 2026 20:21:13 +0000 (+0300) Subject: [3.14] gh-154283: Make threading.get_native_id() unique across processes on DragonFly... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=903265fd16af7b11924c0ec16d546d8b5bf6bba6;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-154283: Make threading.get_native_id() unique across processes on DragonFly (GH-154287) (GH-154297) On DragonFly BSD lwp_gettid() is only unique within a process (the main thread is always LWP 1), so combine it with the process id, like Solaris. (cherry picked from commit 53597df11e2d9f01ade2529c147df24b49685878) Co-authored-by: Claude Opus 4.8 (1M context) --- diff --git a/Misc/NEWS.d/next/Library/2026-07-20-21-36-40.gh-issue-154283.Xip7xE.rst b/Misc/NEWS.d/next/Library/2026-07-20-21-36-40.gh-issue-154283.Xip7xE.rst new file mode 100644 index 000000000000..a278d67e1824 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-20-21-36-40.gh-issue-154283.Xip7xE.rst @@ -0,0 +1,2 @@ +On DragonFly BSD, :func:`threading.get_native_id` now returns a value that is +unique across processes, matching the other platforms. diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index da4058242448..8e7b9589615b 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -407,8 +407,8 @@ PyThread_get_thread_native_id(void) lwpid_t native_id; native_id = _lwp_self(); #elif defined(__DragonFly__) - lwpid_t native_id; - native_id = lwp_gettid(); + // lwp_gettid() is only unique within a process, so combine it with the pid. + unsigned long native_id = (unsigned long)getpid() << 32 | lwp_gettid(); #endif return (unsigned long) native_id; }