Skip to content

sys.thread_info.lock was changed to "pymutex" in 3.15, even though _thread.Lock had already switched to PyMutex in 3.14 and 3.13.1 #152798

Description

@GalaxySnail

Bug report

Bug description:

In GH-134747 and GH-141140, sys.thread_info.lock was changed to "pymutex". However, the implementation of _thread.Lock had already been changed to use PyMutex in Python 3.14 (fca5529), and was backported to 3.13.1 (20242a4). In Python 3.13.1 and later, _thread.RLock is the only synchronization primitive that depends on PyThread_type_lock. And in Python 3.14, _thread.RLock was also changed to use the parking-lot-based _PyRecursiveMutex (67f6e08). However, sys.thread_info.lock remained unchanged: it's still "semaphore" on Linux and None on Windows in Python 3.14.

GH-134747 only changed the implementation of PyThread_type_lock, which is irrelevant to synchronization primitives in the threading module. So changing the value of sys.thread_info.lock to "pymutex" makes its meaning ambiguous. In addition, PyMutex itself still uses platform-dependent synchronization primitives, namely POSIX semaphore, pthread_cond+pthread_mutex, and CreateSemaphore on Windows (ref: https://github.com/python/cpython/blob/main/Python/parking_lot.c), precisely the same families of primitives previously reflected by sys.thread_info.lock.

So I think the change to sys.thread_info.lock should be reverted to avoid confusing users.

cc @vstinner

CPython versions tested on:

3.15

Operating systems tested on:

Linux, Windows

Linked PRs

Activity

  1. Wojusensei commented on Jul 4, 2026

    @Wojusensei
    Contributor

    I'd like to work on this ,plz assign it to me :)

  2. IvyXu420 commented on Jul 7, 2026

    @IvyXu420
  3. vstinner commented on Jul 7, 2026

    @vstinner
    Member

    I suggest closing this issue. Or if something is done, it should be to only enhance the documentation.


    Well, sys.thread_info.lock could be changed to 'pymutex' in Python 3.13, since _thread.allocate_lock() was modified to use PyMutex internally. It has not been done, but Python 3.13 has been released in October 2024. IMO it's now too late to change it.

    In addition, PyMutex itself still uses platform-dependent synchronization primitives, namely POSIX semaphore, pthread_cond+pthread_mutex, and CreateSemaphore on Windows

    That's correct, but I prefer the short string 'pymutex' to refer to PyMutex. If someone needs more details about PyMutex, they can dig into the code, as you did.

    So changing the value of sys.thread_info.lock to "pymutex" makes its meaning ambiguous.

    I don't see how it's confusing. Python now uses PyMutex for threading.Lock, threading.RLock and for the C API PyThread_allocate_lock(). It's used everywhere.

  4. Wojusensei commented on Jul 7, 2026

    @Wojusensei
    Contributor

    thanks for the confirmation and I've opened a PR to update the documentation without changing codes as u suggested:
    https://github.com/python/cpython/pull/153263

  5. GalaxySnail commented on Jul 7, 2026

    @GalaxySnail
    ContributorAuthor

    It has not been done, but Python 3.13 has been released in October 2024. IMO it's now too late to change it.

    100% agree. That's why I proposed to revert this change in 3.15.

    I don't see how it's confusing. Python now uses PyMutex for threading.Lock, threading.RLock and for the C API PyThread_allocate_lock(). It's used everywhere.

    This is because it makes the value of sys.thread_info.lock technically wrong in 3.13 and 3.14. Users can't rely on this value to determine which lock implementation is actually used; instead, they have to check sys.version_info and ignore sys.thread_info.lock.

  6. vstinner commented on Jul 7, 2026

    @vstinner
    Member

    100% agree. That's why I proposed to revert this change in 3.15.

    That's not what I'm saying. I don't suggest a revert. Changing sys.thread_info in 3.15 was a good thing. I'm just saying that it's too late to change sys.thread_info in 3.13 and 3.14 since they are already released (a change can break users relying in the exact value).

    This is because it makes the value of sys.thread_info.lock technically wrong in 3.13 and 3.14. Users can't rely on this value to determine which lock implementation is actually used; instead, they have to check sys.version_info and ignore sys.thread_info.lock.

    I don't consider that it's a big deal. sys.thread_info is mostly here to help debugging CPython issues. I don't see why someone would really bother how locks are implemented in Python.

  7. added a commit that references this issue on Jul 7, 2026
  8. added a commit that references this issue on Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions