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

[3.14] gh-134322: Fixrepr(threading.RLock) (GH-134389)#134528

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 1 commit intopython:3.14frommiss-islington:backport-fade146-3.14
May 22, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
20 changes: 20 additions & 0 deletionsLib/test/lock_tests.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -332,6 +332,26 @@ class RLockTests(BaseLockTests):
"""
Tests for recursive locks.
"""
def test_repr_count(self):
# see gh-134322: check that count values are correct:
# when a rlock is just created,
# in a second thread when rlock is acquired in the main thread.
lock = self.locktype()
self.assertIn("count=0", repr(lock))
self.assertIn("<unlocked", repr(lock))
lock.acquire()
lock.acquire()
self.assertIn("count=2", repr(lock))
self.assertIn("<locked", repr(lock))

result = []
def call_repr():
result.append(repr(lock))
with Bunch(call_repr, 1):
pass
self.assertIn("count=2", result[0])
self.assertIn("<locked", result[0])

def test_reacquire(self):
lock = self.locktype()
lock.acquire()
Expand Down
1 change: 1 addition & 0 deletionsLib/test/test_importlib/test_locks.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,6 +34,7 @@ class ModuleLockAsRLockTests:
# lock status in repr unsupported
test_repr = None
test_locked_repr = None
test_repr_count = None

def tearDown(self):
for splitinit in init.values():
Expand Down
8 changes: 7 additions & 1 deletionModules/_threadmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1208,7 +1208,13 @@ rlock_repr(PyObject *op)
rlockobject *self = rlockobject_CAST(op);
PyThread_ident_t owner = self->lock.thread;
int locked = rlock_locked_impl(self);
size_t count = self->lock.level + 1;
size_t count;
if (locked) {
count = self->lock.level + 1;
}
else {
count = 0;
}
return PyUnicode_FromFormat(
"<%s %s object owner=%" PY_FORMAT_THREAD_IDENT_T " count=%zu at %p>",
locked ? "locked" : "unlocked",
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp