Use test.support.start_threads() in threaded lru_cache tests.
This commit is contained in:
parent
8b2e8b6cce
commit
bf2b3b72d3
|
@ -1120,14 +1120,10 @@ class TestLRU:
|
||||||
sys.setswitchinterval(1e-6)
|
sys.setswitchinterval(1e-6)
|
||||||
try:
|
try:
|
||||||
# create 5 threads in order to fill cache
|
# create 5 threads in order to fill cache
|
||||||
threads = []
|
threads = [threading.Thread(target=full, args=[f, k, k])
|
||||||
for k in range(5):
|
for k in range(5)]
|
||||||
t = threading.Thread(target=full, args=[f, k, k])
|
with support.start_threads(threads):
|
||||||
t.start()
|
pass
|
||||||
threads.append(t)
|
|
||||||
|
|
||||||
for t in threads:
|
|
||||||
t.join()
|
|
||||||
|
|
||||||
hits, misses, maxsize, currsize = f.cache_info()
|
hits, misses, maxsize, currsize = f.cache_info()
|
||||||
self.assertEqual(hits, 45)
|
self.assertEqual(hits, 45)
|
||||||
|
@ -1135,16 +1131,11 @@ class TestLRU:
|
||||||
self.assertEqual(currsize, 5)
|
self.assertEqual(currsize, 5)
|
||||||
|
|
||||||
# create 5 threads in order to fill cache and 1 to clear it
|
# create 5 threads in order to fill cache and 1 to clear it
|
||||||
cleaner = threading.Thread(target=clear, args=[f])
|
threads = [threading.Thread(target=clear, args=[f])]
|
||||||
cleaner.start()
|
threads += [threading.Thread(target=full, args=[f, k, k])
|
||||||
threads = [cleaner]
|
for k in range(5)]
|
||||||
for k in range(5):
|
with support.start_threads(threads):
|
||||||
t = threading.Thread(target=full, args=[f, k, k])
|
pass
|
||||||
t.start()
|
|
||||||
threads.append(t)
|
|
||||||
|
|
||||||
for t in threads:
|
|
||||||
t.join()
|
|
||||||
finally:
|
finally:
|
||||||
sys.setswitchinterval(orig_si)
|
sys.setswitchinterval(orig_si)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue