Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
62f4dad8
Kaydet (Commit)
62f4dad8
authored
May 26, 2014
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 21137: Better repr for threading.Lock()
üst
fa4ed0c1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
6 deletions
+41
-6
_dummy_thread.py
Lib/_dummy_thread.py
+8
-0
lock_tests.py
Lib/test/lock_tests.py
+7
-1
test_locks.py
Lib/test/test_importlib/test_locks.py
+3
-0
threading.py
Lib/threading.py
+8
-2
NEWS
Misc/NEWS
+3
-0
_threadmodule.c
Modules/_threadmodule.c
+12
-3
No files found.
Lib/_dummy_thread.py
Dosyayı görüntüle @
62f4dad8
...
...
@@ -140,6 +140,14 @@ class LockType(object):
def
locked
(
self
):
return
self
.
locked_status
def
__repr__
(
self
):
return
"<
%
s
%
s.
%
s object at
%
s>"
%
(
"locked"
if
self
.
locked_status
else
"unlocked"
,
self
.
__class__
.
__module__
,
self
.
__class__
.
__qualname__
,
hex
(
id
(
self
))
)
# Used to signal that interrupt_main was called in a "thread"
_interrupt
=
False
# True when not executing in a "thread"
...
...
Lib/test/lock_tests.py
Dosyayı görüntüle @
62f4dad8
...
...
@@ -82,7 +82,13 @@ class BaseLockTests(BaseTestCase):
def
test_repr
(
self
):
lock
=
self
.
locktype
()
repr
(
lock
)
self
.
assertRegex
(
repr
(
lock
),
"<unlocked .* object (.*)?at .*>"
)
del
lock
def
test_locked_repr
(
self
):
lock
=
self
.
locktype
()
lock
.
acquire
()
self
.
assertRegex
(
repr
(
lock
),
"<locked .* object (.*)?at .*>"
)
del
lock
def
test_acquire_destroy
(
self
):
...
...
Lib/test/test_importlib/test_locks.py
Dosyayı görüntüle @
62f4dad8
...
...
@@ -31,6 +31,9 @@ if threading is not None:
test_timeout
=
None
# _release_save() unsupported
test_release_save_unacquired
=
None
# lock status in repr unsupported
test_repr
=
None
test_locked_repr
=
None
LOCK_TYPES
=
{
kind
:
splitinit
.
_bootstrap
.
_ModuleLock
for
kind
,
splitinit
in
init
.
items
()}
...
...
Lib/threading.py
Dosyayı görüntüle @
62f4dad8
...
...
@@ -106,8 +106,14 @@ class _RLock:
owner
=
_active
[
owner
]
.
name
except
KeyError
:
pass
return
"<
%
s owner=
%
r count=
%
d>"
%
(
self
.
__class__
.
__name__
,
owner
,
self
.
_count
)
return
"<
%
s
%
s.
%
s object owner=
%
r count=
%
d at
%
s>"
%
(
"locked"
if
self
.
_block
.
locked
()
else
"unlocked"
,
self
.
__class__
.
__module__
,
self
.
__class__
.
__qualname__
,
owner
,
self
.
_count
,
hex
(
id
(
self
))
)
def
acquire
(
self
,
blocking
=
True
,
timeout
=-
1
):
"""Acquire a lock, blocking or non-blocking.
...
...
Misc/NEWS
Dosyayı görüntüle @
62f4dad8
...
...
@@ -97,6 +97,9 @@ Library
- Issue #21513: Speedup some properties of IP addresses (IPv4Address,
IPv6Address) such as .is_private or .is_multicast.
- Issue #21137: Improve the repr for threading.Lock() and its variants
by showing the "locked" or "unlocked" status. Patch by Berker Peksag.
- Issue #21538: The plistlib module now supports loading of binary plist files
when reference or offset size is not a power of two.
...
...
Modules/_threadmodule.c
Dosyayı görüntüle @
62f4dad8
...
...
@@ -192,6 +192,13 @@ PyDoc_STRVAR(locked_doc,
\n
\
Return whether the lock is in the locked state."
);
static
PyObject
*
lock_repr
(
lockobject
*
self
)
{
return
PyUnicode_FromFormat
(
"<%s %s object at %p>"
,
self
->
locked
?
"locked"
:
"unlocked"
,
Py_TYPE
(
self
)
->
tp_name
,
self
);
}
static
PyMethodDef
lock_methods
[]
=
{
{
"acquire_lock"
,
(
PyCFunction
)
lock_PyThread_acquire_lock
,
METH_VARARGS
|
METH_KEYWORDS
,
acquire_doc
},
...
...
@@ -223,7 +230,7 @@ static PyTypeObject Locktype = {
0
,
/*tp_getattr*/
0
,
/*tp_setattr*/
0
,
/*tp_reserved*/
0
,
/*tp_repr*/
(
reprfunc
)
lock_repr
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_mapping*/
...
...
@@ -475,8 +482,10 @@ rlock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static
PyObject
*
rlock_repr
(
rlockobject
*
self
)
{
return
PyUnicode_FromFormat
(
"<%s owner=%ld count=%lu>"
,
Py_TYPE
(
self
)
->
tp_name
,
self
->
rlock_owner
,
self
->
rlock_count
);
return
PyUnicode_FromFormat
(
"<%s %s object owner=%ld count=%lu at %p>"
,
self
->
rlock_count
?
"locked"
:
"unlocked"
,
Py_TYPE
(
self
)
->
tp_name
,
self
->
rlock_owner
,
self
->
rlock_count
,
self
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment