Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
YvesDup opened this issue May 20, 2025 · 3 comments
Closed

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

YvesDup opened this issue May 20, 2025 · 3 comments
Labels
3.14 bugs and security fixes 3.15 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@YvesDup
Copy link
Contributor

YvesDup commented May 20, 2025

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

@YvesDup YvesDup added the type-bug An unexpected behavior, bug, or error label May 20, 2025
@picnixz picnixz added stdlib Python modules in the Lib dir extension-modules C modules in the Modules dir 3.14 bugs and security fixes 3.15 new features, bugs and security fixes labels May 20, 2025
@picnixz
Copy link
Member

picnixz commented May 20, 2025

cc @sobolevn

@picnixz
Copy link
Member

picnixz commented May 20, 2025

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

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

@picnixz picnixz removed the extension-modules C modules in the Modules dir label May 20, 2025
@YvesDup
Copy link
Contributor Author

YvesDup commented May 20, 2025

These 2 bugs were introduced by #115944

vstinner pushed a commit that referenced this issue May 22, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 22, 2025
…H-134368)

(cherry picked from commit 3effede)

Co-authored-by: Duprat <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
vstinner pushed a commit that referenced this issue May 22, 2025
) (#134510)

gh-134323: Fix the new `threading.RLock.locked` method (GH-134368)
(cherry picked from commit 3effede)

Co-authored-by: Duprat <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 bugs and security fixes 3.15 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants