mirror of
https://github.com/python/cpython.git
synced 2025-08-06 09:59:07 +00:00
Fix (hopefully) occasional failures in test_threaded_import.
`done` could be released multiple times because of concurrent execution. We convert it to an Event, where calling set() multiple times is not a problem.
This commit is contained in:
parent
d24fc5d7c4
commit
a62cbf7cce
1 changed files with 4 additions and 5 deletions
|
@ -33,7 +33,7 @@ def task(N, done, done_tasks, errors):
|
||||||
done_tasks.append(thread.get_ident())
|
done_tasks.append(thread.get_ident())
|
||||||
finished = len(done_tasks) == N
|
finished = len(done_tasks) == N
|
||||||
if finished:
|
if finished:
|
||||||
done.release()
|
done.set()
|
||||||
|
|
||||||
# Create a circular import structure: A -> C -> B -> D -> A
|
# Create a circular import structure: A -> C -> B -> D -> A
|
||||||
# NOTE: `time` is already loaded and therefore doesn't threaten to deadlock.
|
# NOTE: `time` is already loaded and therefore doesn't threaten to deadlock.
|
||||||
|
@ -99,8 +99,7 @@ class ThreadedImportTests(unittest.TestCase):
|
||||||
# This triggers on, e.g., from test import autotest.
|
# This triggers on, e.g., from test import autotest.
|
||||||
raise unittest.SkipTest("can't run when import lock is held")
|
raise unittest.SkipTest("can't run when import lock is held")
|
||||||
|
|
||||||
done = thread.allocate_lock()
|
done = threading.Event()
|
||||||
done.acquire()
|
|
||||||
for N in (20, 50) * 3:
|
for N in (20, 50) * 3:
|
||||||
if verbose:
|
if verbose:
|
||||||
print("Trying", N, "threads ...", end=' ')
|
print("Trying", N, "threads ...", end=' ')
|
||||||
|
@ -112,13 +111,13 @@ class ThreadedImportTests(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
errors = []
|
errors = []
|
||||||
done_tasks = []
|
done_tasks = []
|
||||||
|
done.clear()
|
||||||
for i in range(N):
|
for i in range(N):
|
||||||
thread.start_new_thread(task, (N, done, done_tasks, errors,))
|
thread.start_new_thread(task, (N, done, done_tasks, errors,))
|
||||||
done.acquire()
|
done.wait(60)
|
||||||
self.assertFalse(errors)
|
self.assertFalse(errors)
|
||||||
if verbose:
|
if verbose:
|
||||||
print("OK.")
|
print("OK.")
|
||||||
done.release()
|
|
||||||
|
|
||||||
def test_parallel_module_init(self):
|
def test_parallel_module_init(self):
|
||||||
self.check_parallel_module_init()
|
self.check_parallel_module_init()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue