Author: Armin Rigo <[email protected]>
Branch:
Changeset: r93581:c166d499b6d8
Date: 2017-12-27 07:37 +0100
http://bitbucket.org/pypy/pypy/changeset/c166d499b6d8/
Log: Issue #2689
thread.Lock objects are weakrefable in CPython
diff --git a/pypy/module/thread/os_lock.py b/pypy/module/thread/os_lock.py
--- a/pypy/module/thread/os_lock.py
+++ b/pypy/module/thread/os_lock.py
@@ -7,7 +7,7 @@
from pypy.module.thread.error import wrap_thread_error
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.interpreter.typedef import TypeDef
+from pypy.interpreter.typedef import TypeDef, make_weakref_descr
from pypy.interpreter.error import oefmt
from rpython.rlib.rarithmetic import r_longlong, ovfcheck_float_to_longlong
@@ -150,6 +150,7 @@
locked = descr_locked,
__enter__ = descr__enter__,
__exit__ = descr__exit__,
+ __weakref__ = make_weakref_descr(Lock),
# Obsolete synonyms
acquire_lock = descr_acquire,
release_lock = descr_release,
diff --git a/pypy/module/thread/test/test_lock.py
b/pypy/module/thread/test/test_lock.py
--- a/pypy/module/thread/test/test_lock.py
+++ b/pypy/module/thread/test/test_lock.py
@@ -52,6 +52,10 @@
assert feedback == [42]
assert lock.locked() is False
+ def test_weakrefable(self):
+ import thread, weakref
+ weakref.ref(thread.allocate_lock())
+
def test_timeout(self):
import thread
lock = thread.allocate_lock()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit