Skip to content

Commit 6531253

Browse files
[3.13] gh-154283: Make threading.get_native_id() unique across processes on DragonFly (GH-154287) (GH-154298)
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 53597df) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4beda40 commit 6531253

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
On DragonFly BSD, :func:`threading.get_native_id` now returns a value that is
2+
unique across processes, matching the other platforms.

Python/thread_pthread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ PyThread_get_thread_native_id(void)
407407
lwpid_t native_id;
408408
native_id = _lwp_self();
409409
#elif defined(__DragonFly__)
410-
lwpid_t native_id;
411-
native_id = lwp_gettid();
410+
// lwp_gettid() is only unique within a process, so combine it with the pid.
411+
unsigned long native_id = (unsigned long)getpid() << 32 | lwp_gettid();
412412
#endif
413413
return (unsigned long) native_id;
414414
}

0 commit comments

Comments
 (0)