[3.15] gh-154283: Make threading.get_native_id() unique across processes on DragonFly (GH-154287) (GH-154293)

serhiy-storchaka <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/387f7cd81d285ca9ed9a95b2376a2290a3241f20
commit: 387f7cd81d285ca9ed9a95b2376a2290a3241f20
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-07-20T20:20:57Z
summary:

[3.15] gh-154283: Make threading.get_native_id() unique across processes on DragonFly (GH-154287) (GH-154293)

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: Serhiy Storchaka <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-07-20-21-36-40.gh-issue-154283.Xip7xE.rst
M Python/thread_pthread.h

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 00000000000000..a278d67e1824d5
--- /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 8496f91db2eec2..de93178576e6ec 100644
--- a/Python/thread_pthread.h
+++ b/Python/thread_pthread.h
@@ -399,8 +399,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();
 #elif defined(__sun__) && SIZEOF_LONG >= 8
     unsigned long native_id = (unsigned long)getpid() << 32 | thr_self();
 #endif

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.