Skip to content

The new threading.RLock.locked() method fails #134323

Closed

Description

@YvesDup

Bug report

Bug description:

import threading

def main():
    r = threading.RLock()
    print(f"{r = }")
    t = threading.Thread(target=r.acquire)
    t.start()
    t.join()
    print(f"{r = }")
    print(f"{r.locked() = } at {hex(id(r))}")

if __name__ == '__main__':
    main()

Output is:

r = <unlocked _thread.RLock object owner=0 count=1 at 0x105a98720>
r = <locked _thread.RLock object owner=6106329088 count=1 at 0x105a98720>
r.locked() = False at 0x105a98720

Error is located at:

cpython/Lib/threading.py

Lines 238 to 240 in 28625d4

def locked(self):
"""Return whether this object is locked."""
return self._count > 0

The return instruction must be: return self._block.locked().

I can submit a PR quickly.

CPython versions tested on:

CPython main branch, 3.14

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    3.14bugs and security fixes
    3.15bugs and security fixes
    on May 20, 2025
  2. picnixz commented on May 20, 2025

    @picnixz
    Member
  3. picnixz commented on May 20, 2025

    @picnixz
    Member

    Didn't we already have a report for this one actually?

    EDIT: It was related but not this one in particular: #132561.

  4. YvesDup commented on May 20, 2025

    @YvesDup
    ContributorAuthor

    These 2 bugs were introduced by #115944

  5. added a commit that references this issue on May 22, 2025
  6. added a commit that references this issue on May 22, 2025
  7. added a commit that references this issue on May 22, 2025
  8. added a commit that references this issue on May 26, 2025
  9. added a commit that references this issue on Jul 12, 2025
  10. added a commit that references this issue on Aug 4, 2025
  11. added a commit that references this issue on Jun 2, 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

    3.14bugs and security fixes3.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions