Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-134323: Fix the newthreading.RLock.locked method#134368

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 10 commits intopython:mainfromYvesDup:rlock-threading-locked-failed
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletionsLib/test/lock_tests.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -370,6 +370,19 @@ def test_locked(self):
lock.release()
self.assertFalse(lock.locked())

def test_locked_2threads(self):
l = []
rlock = self.locktype()
def acquire():
rlock.acquire()
l.append(rlock.locked())

with Bunch(acquire, 1):
pass
self.assertTrue(rlock.locked())
self.assertTrue(l[0])
del rlock

def test_release_save_unacquired(self):
# Cannot _release_save an unacquired lock
lock = self.locktype()
Expand Down
2 changes: 1 addition & 1 deletionLib/threading.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -237,7 +237,7 @@ def __exit__(self, t, v, tb):

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

# Internal methods used by condition variables

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Fix the public :meth:`locked<threading.RLock>` and its implementation in the ``_thread`` module.
Also adding a unit test in ``lock_test.py`` file.
8 changes: 6 additions & 2 deletionsModules/_threadmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1110,8 +1110,12 @@ Release the lock.");
static PyObject *
rlock_locked(PyObject *op, PyObject *Py_UNUSED(ignored))
{
rlockobject *self = rlockobject_CAST(op);
int is_locked = _PyRecursiveMutex_IsLockedByCurrentThread(&self->lock);
/*
see gh-134323: the `_PyRecursiveMutex_IsLocked` function does not exist, so we cast the `op`
to `lockobject` in order to call `PyMutex_IsLocked`.
*/
lockobject *self = lockobject_CAST(op);
int is_locked = PyMutex_IsLocked(&self->lock);
return PyBool_FromLong(is_locked);
}

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp