diff options
author | Christian Heimes <christian@cheimes.de> | 2008-01-19 15:06:09 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-01-19 15:06:09 (GMT) |
commit | 95016e71ea7ea9394c0b72f7614ece193d0b3307 (patch) | |
tree | 19fe5201da674768f6bbdc7d59900f8d862130ae /Lib | |
parent | 71a0451f67b41e326a14f4ae1481cb72e462881d (diff) | |
download | cpython-95016e71ea7ea9394c0b72f7614ece193d0b3307.zip cpython-95016e71ea7ea9394c0b72f7614ece193d0b3307.tar.gz cpython-95016e71ea7ea9394c0b72f7614ece193d0b3307.tar.bz2 |
Update for threading.local test.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_threading_local.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Lib/test/test_threading_local.py b/Lib/test/test_threading_local.py index 7c2b9f4..b7dd538 100644 --- a/Lib/test/test_threading_local.py +++ b/Lib/test/test_threading_local.py @@ -3,6 +3,7 @@ from doctest import DocTestSuite from test import test_support import threading import weakref +import gc class Weak(object): pass @@ -13,19 +14,34 @@ def target(local, weaklist): weaklist.append(weakref.ref(weak)) class ThreadingLocalTest(unittest.TestCase): + def test_local_refs(self): + self._local_refs(20) + self._local_refs(50) + self._local_refs(100) + + def _local_refs(self, n): local = threading.local() weaklist = [] - n = 20 for i in range(n): t = threading.Thread(target=target, args=(local, weaklist)) t.start() t.join() + del t + + gc.collect() self.assertEqual(len(weaklist), n) + + # XXX threading.local keeps the local of the last stopped thread alive. deadlist = [weak for weak in weaklist if weak() is None] - # XXX threading.local keeps the local of the last stopped thread alive self.assertEqual(len(deadlist), n-1) + # Assignment to the same thread local frees it sometimes (!) + local.someothervar = None + gc.collect() + deadlist = [weak for weak in weaklist if weak() is None] + self.assert_(len(deadlist) in (n-1, n), (n, len(deadlist))) + def test_main(): suite = unittest.TestSuite() suite.addTest(DocTestSuite('_threading_local')) |