|
@@ -18,7 +18,9 @@ def get_executor_for_config(worker_num: int, thread_name_prefix: str) -> Executo
|
|
Executor: A ThreadPoolExecutor instance.
|
|
Executor: A ThreadPoolExecutor instance.
|
|
|
|
|
|
"""
|
|
"""
|
|
- executor = ThreadPoolExecutor(max_workers=worker_num, thread_name_prefix=thread_name_prefix)
|
|
|
|
|
|
+ executor = ThreadPoolExecutor(
|
|
|
|
+ max_workers=worker_num, thread_name_prefix=thread_name_prefix
|
|
|
|
+ )
|
|
atexit.register(executor.shutdown, wait=False)
|
|
atexit.register(executor.shutdown, wait=False)
|
|
return executor
|
|
return executor
|
|
|
|
|
|
@@ -38,7 +40,7 @@ def run_with_executor(executor: Executor, func, tasks: List, timeout: int):
|
|
|
|
|
|
Raises:
|
|
Raises:
|
|
Exception: If any of the tasks raise an exception.
|
|
Exception: If any of the tasks raise an exception.
|
|
- """
|
|
|
|
|
|
+
|
|
futures = [executor.submit(lambda args: func(*args), task) for task in tasks]
|
|
futures = [executor.submit(lambda args: func(*args), task) for task in tasks]
|
|
done, _ = concurrent.futures.wait(futures, return_when=concurrent.futures.FIRST_EXCEPTION, timeout=timeout)
|
|
done, _ = concurrent.futures.wait(futures, return_when=concurrent.futures.FIRST_EXCEPTION, timeout=timeout)
|
|
|
|
|
|
@@ -50,3 +52,17 @@ def run_with_executor(executor: Executor, func, tasks: List, timeout: int):
|
|
if future.done():
|
|
if future.done():
|
|
results.append(future.result())
|
|
results.append(future.result())
|
|
return results
|
|
return results
|
|
|
|
+ """
|
|
|
|
+
|
|
|
|
+ results = []
|
|
|
|
+ # Iterate over tasks and execute them sequentially
|
|
|
|
+ for task in tasks:
|
|
|
|
+ future = executor.submit(lambda args: func(*args), task)
|
|
|
|
+ # Wait for the task to complete (with timeout)
|
|
|
|
+ try:
|
|
|
|
+ result = future.result(timeout=timeout)
|
|
|
|
+ results.append(result)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+
|
|
|
|
+ return results
|