[pypy-commit] pypy default: thread._local() should be weakrefable
arigo
pypy.commits at gmail.com
Wed Dec 27 01:49:54 EST 2017
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r93582:ecedc8227476
Date: 2017-12-27 07:44 +0100
http://bitbucket.org/pypy/pypy/changeset/ecedc8227476/
Log: thread._local() should be weakrefable
diff --git a/pypy/module/thread/os_local.py b/pypy/module/thread/os_local.py
--- a/pypy/module/thread/os_local.py
+++ b/pypy/module/thread/os_local.py
@@ -4,7 +4,7 @@
from pypy.interpreter.error import oefmt
from pypy.interpreter.executioncontext import ExecutionContext
from pypy.interpreter.typedef import (TypeDef, interp2app, GetSetProperty,
- descr_get_dict)
+ descr_get_dict, make_weakref_descr)
from rpython.rlib.rshrinklist import AbstractShrinkList
@@ -90,6 +90,7 @@
__doc__ = "Thread-local data",
__new__ = interp2app(Local.descr_local__new__.im_func),
__dict__ = GetSetProperty(descr_get_dict, cls=Local),
+ __weakref__ = make_weakref_descr(Local),
)
def thread_is_stopping(ec):
diff --git a/pypy/module/thread/test/test_local.py b/pypy/module/thread/test/test_local.py
--- a/pypy/module/thread/test/test_local.py
+++ b/pypy/module/thread/test/test_local.py
@@ -102,6 +102,10 @@
self.waitfor(lambda: len(done) == 5, delay=2)
assert len(done) == 5
+ def test_weakrefable(self):
+ import thread, weakref
+ weakref.ref(thread._local())
+
def test_local_is_not_immortal(self):
import thread, gc, time
class Local(thread._local):
More information about the pypy-commit
mailing list