summaryrefslogtreecommitdiffstats
path: root/Modules/_threadmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2014-05-26 01:22:35 (GMT)
committerRaymond Hettinger <python@rcn.com>2014-05-26 01:22:35 (GMT)
commit62f4dad81607d8d0a70223ef3feacdfd3aa5e898 (patch)
tree5e4c3b7ccb6ab56240b77da3946c4e0a301c72f3 /Modules/_threadmodule.c
parentfa4ed0c145f2e17ccd59c2180cbf7be07c8c872d (diff)
downloadcpython-62f4dad81607d8d0a70223ef3feacdfd3aa5e898.zip
cpython-62f4dad81607d8d0a70223ef3feacdfd3aa5e898.tar.gz
cpython-62f4dad81607d8d0a70223ef3feacdfd3aa5e898.tar.bz2
Issue 21137: Better repr for threading.Lock()
Diffstat (limited to 'Modules/_threadmodule.c')
-rw-r--r--Modules/_threadmodule.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 9925b0e..b68c177 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -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);
}