From 55f503c5c11fe56cfcd10e772275b2c90c2ecb19 Mon Sep 17 00:00:00 2001 From: zulissimeta <122578103+zulissimeta@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:34:01 -0700 Subject: [PATCH 1/5] Update prep.py --- src/quacc/runners/prep.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/quacc/runners/prep.py b/src/quacc/runners/prep.py index ee2a885471..8625d805a8 100644 --- a/src/quacc/runners/prep.py +++ b/src/quacc/runners/prep.py @@ -4,8 +4,10 @@ import logging import os +import shutil +import time from pathlib import Path -from shutil import move, rmtree +from shutil import move from typing import TYPE_CHECKING from monty.shutil import gzip_dir @@ -83,7 +85,6 @@ def calc_setup( return tmpdir, job_results_dir - def calc_cleanup( atoms: Atoms | None, tmpdir: Path | str, job_results_dir: Path | str ) -> None: @@ -174,3 +175,24 @@ def terminate(tmpdir: Path | str, exception: Exception) -> None: symlink_path.symlink_to(job_failed_dir, target_is_directory=True) raise JobFailure(job_failed_dir, message=msg, parent_error=exception) from exception + +def rmtree(*args, max_retries=3, retry_wait=10, **kwargs): + """ + rmtree that will retry if we get common NFS errors (files still being deleted, etc) + """ + if 'onerror' in kwargs and kwargs['onerror'] is not None: + shutil.rmtree(*args, **kwargs) + return + + for i in range(max_retries): + try: + shutil.rmtree(*args, **kwargs) + return + except OSError as e: + if i == max_retries: + raise + elif e.errno in {errno.ENOTEMPTY, errno.EBUSY}: + time.sleep(retry_wait) + pass + else: + raise From 9e72d24a61b0803b00c8f276be31803d1ced6c1c Mon Sep 17 00:00:00 2001 From: zulissimeta <122578103+zulissimeta@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:35:29 -0700 Subject: [PATCH 2/5] Update prep.py --- src/quacc/runners/prep.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/quacc/runners/prep.py b/src/quacc/runners/prep.py index 8625d805a8..f7ed8bf368 100644 --- a/src/quacc/runners/prep.py +++ b/src/quacc/runners/prep.py @@ -179,6 +179,7 @@ def terminate(tmpdir: Path | str, exception: Exception) -> None: def rmtree(*args, max_retries=3, retry_wait=10, **kwargs): """ rmtree that will retry if we get common NFS errors (files still being deleted, etc) + Adapted from https://github.com/teojgo/reframe/blob/master/reframe/utility/osext.py """ if 'onerror' in kwargs and kwargs['onerror'] is not None: shutil.rmtree(*args, **kwargs) From c1be5abaed5e180eb91a8ec84415d2af650073ed Mon Sep 17 00:00:00 2001 From: zulissimeta <122578103+zulissimeta@users.noreply.github.com> Date: Mon, 19 Aug 2024 09:04:40 -0700 Subject: [PATCH 3/5] Update prep.py --- src/quacc/runners/prep.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/quacc/runners/prep.py b/src/quacc/runners/prep.py index f7ed8bf368..88811340cf 100644 --- a/src/quacc/runners/prep.py +++ b/src/quacc/runners/prep.py @@ -2,6 +2,7 @@ from __future__ import annotations +import errno import logging import os import shutil From 1952c18a91fb0cbdc23b9271bf4133d85b8ce4cd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:07:43 +0000 Subject: [PATCH 4/5] pre-commit auto-fixes --- src/quacc/runners/prep.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/quacc/runners/prep.py b/src/quacc/runners/prep.py index 88811340cf..18f667c384 100644 --- a/src/quacc/runners/prep.py +++ b/src/quacc/runners/prep.py @@ -86,6 +86,7 @@ def calc_setup( return tmpdir, job_results_dir + def calc_cleanup( atoms: Atoms | None, tmpdir: Path | str, job_results_dir: Path | str ) -> None: @@ -177,12 +178,13 @@ def terminate(tmpdir: Path | str, exception: Exception) -> None: raise JobFailure(job_failed_dir, message=msg, parent_error=exception) from exception + def rmtree(*args, max_retries=3, retry_wait=10, **kwargs): """ rmtree that will retry if we get common NFS errors (files still being deleted, etc) Adapted from https://github.com/teojgo/reframe/blob/master/reframe/utility/osext.py """ - if 'onerror' in kwargs and kwargs['onerror'] is not None: + if "onerror" in kwargs and kwargs["onerror"] is not None: shutil.rmtree(*args, **kwargs) return @@ -195,6 +197,5 @@ def rmtree(*args, max_retries=3, retry_wait=10, **kwargs): raise elif e.errno in {errno.ENOTEMPTY, errno.EBUSY}: time.sleep(retry_wait) - pass else: raise From 8069d40c0058ba011687e903415bb81ec8acad88 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:12:48 +0000 Subject: [PATCH 5/5] pre-commit auto-fixes --- src/quacc/runners/prep.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/quacc/runners/prep.py b/src/quacc/runners/prep.py index f619bc4ba0..5025a5c24e 100644 --- a/src/quacc/runners/prep.py +++ b/src/quacc/runners/prep.py @@ -3,11 +3,9 @@ from __future__ import annotations import errno -import logging import os import shutil import time -import os from logging import getLogger from pathlib import Path from shutil import move @@ -197,7 +195,7 @@ def rmtree(*args, max_retries=3, retry_wait=10, **kwargs): except OSError as e: if i == max_retries: raise - elif e.errno in {errno.ENOTEMPTY, errno.EBUSY}: + if e.errno in {errno.ENOTEMPTY, errno.EBUSY}: time.sleep(retry_wait) else: raise