diff --git a/src/ert/run_models/base_run_model.py b/src/ert/run_models/base_run_model.py index f8ae3d3eaba..b5ba5db6f98 100644 --- a/src/ert/run_models/base_run_model.py +++ b/src/ert/run_models/base_run_model.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import concurrent.futures import copy import dataclasses import functools @@ -88,6 +89,11 @@ class ErtRunError(Exception): pass +def delete_runpath(run_path: str) -> None: + if os.path.exists(run_path): + shutil.rmtree(run_path) + + class _LogAggregration(logging.Handler): def __init__(self, messages: MutableSequence[str]) -> None: self.messages = messages @@ -696,9 +702,8 @@ def get_number_of_successful_realizations(self) -> int: @log_duration(logger, logging.INFO) def rm_run_path(self) -> None: - for run_path in self.paths: - if Path(run_path).exists(): - shutil.rmtree(run_path) + with concurrent.futures.ThreadPoolExecutor() as executor: + executor.map(delete_runpath, self.paths) def validate_successful_realizations_count(self) -> None: successful_realizations_count = self.get_number_of_successful_realizations()