diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-08-09 22:41:38 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-08-09 22:41:38 (GMT) |
commit | 87d5260362faf07c5332679aa27e35aef5dd3a34 (patch) | |
tree | 3464d5c0861599c1a7a2b106a062b4bd6eea4358 /Lib | |
parent | 7a956cc74e701f3de1b74f4b2a514975731d23d2 (diff) | |
download | cpython-87d5260362faf07c5332679aa27e35aef5dd3a34.zip cpython-87d5260362faf07c5332679aa27e35aef5dd3a34.tar.gz cpython-87d5260362faf07c5332679aa27e35aef5dd3a34.tar.bz2 |
Merged revisions 83918 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r83918 | antoine.pitrou | 2010-08-10 00:38:19 +0200 (mar., 10 août 2010) | 5 lines
Issue #3757: thread-local objects now support cyclic garbage collection.
Thread-local objects involved in reference cycles will be deallocated
timely by the cyclic GC, even if the underlying thread is still running.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_threading_local.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/test/test_threading_local.py b/Lib/test/test_threading_local.py index 84523ad..0c9f4d9 100644 --- a/Lib/test/test_threading_local.py +++ b/Lib/test/test_threading_local.py @@ -38,9 +38,9 @@ class BaseLocalTest: gc.collect() self.assertEqual(len(weaklist), n) - # XXX threading.local keeps the local of the last stopped thread alive. + # XXX _threading_local keeps the local of the last stopped thread alive. deadlist = [weak for weak in weaklist if weak() is None] - self.assertEqual(len(deadlist), n-1) + self.assertIn(len(deadlist), (n-1, n)) # Assignment to the same thread local frees it sometimes (!) local.someothervar = None @@ -116,6 +116,20 @@ class BaseLocalTest: class ThreadLocalTest(unittest.TestCase, BaseLocalTest): _local = _thread._local + # Fails for the pure Python implementation + def test_cycle_collection(self): + class X: + pass + + x = X() + x.local = self._local() + x.local.x = x + wr = weakref.ref(x) + del x + gc.collect() + self.assertIs(wr(), None) + + class PyThreadingLocalTest(unittest.TestCase, BaseLocalTest): _local = _threading_local.local |