diff options
author | Robert Guo <robert.guo@mongodb.com> | 2022-05-31 14:37:42 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-31 15:03:45 +0000 |
commit | 86cb7ea3649b2190958a1645de9d3df4a529fc90 (patch) | |
tree | d151ad13d193180966201ec4e619ec4e422313cc /buildscripts/linter/parallel.py | |
parent | 2fe7afd99f8158306415470286622c3712bebce3 (diff) | |
download | mongo-r6.0.0-rc8.tar.gz |
SERVER-65672 upgrade python packages to support 3.10r6.0.0-rc8
Diffstat (limited to 'buildscripts/linter/parallel.py')
-rw-r--r-- | buildscripts/linter/parallel.py | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/buildscripts/linter/parallel.py b/buildscripts/linter/parallel.py index 8c38f6a3294..25a6f0d7e75 100644 --- a/buildscripts/linter/parallel.py +++ b/buildscripts/linter/parallel.py @@ -9,7 +9,11 @@ from typing import Any, Callable, List def parallel_process(items, func): # type: (List[Any], Callable[[Any], bool]) -> bool - """Run a set of work items to completion and wait.""" + """ + Run a set of work items to completion and wait. + + :returns whether all tasks were successful. + """ try: cpus = cpu_count() except NotImplementedError: @@ -17,20 +21,16 @@ def parallel_process(items, func): task_queue = queue.Queue() # type: queue.Queue - # Use a list so that worker function will capture this variable - pp_event = threading.Event() - pp_result = [True] - pp_lock = threading.Lock() + has_failure_event = threading.Event() def worker(): # type: () -> None """Worker thread to process work items in parallel.""" - while not pp_event.is_set(): + while True: try: item = task_queue.get_nowait() except queue.Empty: # if the queue is empty, exit the worker thread - pp_event.set() return try: @@ -39,13 +39,8 @@ def parallel_process(items, func): # Tell the queue we finished with the item task_queue.task_done() - # Return early if we fail, and signal we are done if not ret: - with pp_lock: - pp_result[0] = False - - pp_event.set() - return + has_failure_event.set() # Enqueue all the work we want to process for item in items: @@ -62,10 +57,10 @@ def parallel_process(items, func): # Wait for the threads to finish # Loop with a timeout so that we can process Ctrl-C interrupts - while not pp_event.wait(1): + while not queue.Empty: time.sleep(1) for thread in threads: thread.join() - return pp_result[0] + return not has_failure_event.is_set() |