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-134322: fix the__repr__ value ofthreading.RLock from_threadmodule, when just created#134389

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 5 commits intopython:mainfromYvesDup:rlock-threading-erronous-count
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
NextNext commit
Apply last suggestions
  • Loading branch information
@YvesDup
YvesDup committedMay 22, 2025
commit6487bef70a050c94e76fe93fa29f8460dd46c518
14 changes: 7 additions & 7 deletionsLib/test/lock_tests.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -340,7 +340,7 @@ class RLockTests(BaseLockTests):
def test_repr_count(self):
# see gh-134322: check that count values are correct:
# when a rlock is just created,
# in asecondary thread when rlock is acquired in the main thread.
# in asecond thread when rlock is acquired in the main thread.
lock = self.locktype()
self.assertIn("count=0", repr(lock))
self.assertIn("<unlocked", repr(lock))
Expand All@@ -349,13 +349,13 @@ def test_repr_count(self):
self.assertIn("count=2", repr(lock))
self.assertIn("<locked", repr(lock))

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

def test_reacquire(self):
lock = self.locktype()
Expand Down
12 changes: 5 additions & 7 deletionsModules/_threadmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1022,15 +1022,12 @@ rlock_traverse(PyObject *self, visitproc visit, void *arg)
return 0;
}

/*
helper function used by rlock_locked and rlock_repr.
*/
static int
rlock_locked_impl(rlockobject *self) {
rlock_locked_impl(rlockobject *self)
{
return PyMutex_IsLocked(&self->lock.mutex);
}


static void
rlock_dealloc(PyObject *self)
{
Expand DownExpand Up@@ -1227,16 +1224,17 @@ 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;
if (rlock_locked_impl(self)) {
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>",
owner ? "locked" : "unlocked",
locked ? "locked" : "unlocked",
Py_TYPE(self)->tp_name, owner,
count, self);
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp