Skip to content

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

Closed
@YvesDup

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions