[Python-checkins] cpython (merge 3.5 -> default): Use test.support.start_threads() in threaded lru_cache tests.

serhiy.storchaka python-checkins at python.org
Sat May 30 14:51:53 CEST 2015


https://hg.python.org/cpython/rev/ab5aaeaee5ac
changeset:   96374:ab5aaeaee5ac
parent:      96372:2acc30d24edc
parent:      96373:6cce19c280df
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sat May 30 15:49:42 2015 +0300
summary:
  Use test.support.start_threads() in threaded lru_cache tests.

files:
  Lib/test/test_functools.py |  27 ++++++++-----------------
  1 files changed, 9 insertions(+), 18 deletions(-)


diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -1120,14 +1120,10 @@
         sys.setswitchinterval(1e-6)
         try:
             # create 5 threads in order to fill cache
-            threads = []
-            for k in range(5):
-                t = threading.Thread(target=full, args=[f, k, k])
-                t.start()
-                threads.append(t)
-
-            for t in threads:
-                t.join()
+            threads = [threading.Thread(target=full, args=[f, k, k])
+                       for k in range(5)]
+            with support.start_threads(threads):
+                pass
 
             hits, misses, maxsize, currsize = f.cache_info()
             self.assertEqual(hits, 45)
@@ -1135,16 +1131,11 @@
             self.assertEqual(currsize, 5)
 
             # create 5 threads in order to fill cache and 1 to clear it
-            cleaner = threading.Thread(target=clear, args=[f])
-            cleaner.start()
-            threads = [cleaner]
-            for k in range(5):
-                t = threading.Thread(target=full, args=[f, k, k])
-                t.start()
-                threads.append(t)
-
-            for t in threads:
-                t.join()
+            threads = [threading.Thread(target=clear, args=[f])]
+            threads += [threading.Thread(target=full, args=[f, k, k])
+                        for k in range(5)]
+            with support.start_threads(threads):
+                pass
         finally:
             sys.setswitchinterval(orig_si)
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list