Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rmtree for nfs #2434

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/quacc/runners/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

from __future__ import annotations

import errno
import os
import shutil
import time
from logging import getLogger
from pathlib import Path
from shutil import move, rmtree
from shutil import move
from typing import TYPE_CHECKING

from monty.shutil import gzip_dir
Expand Down Expand Up @@ -174,3 +177,25 @@
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're good with a 10 s default? Not too long for you?

"""
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
"""
Comment on lines +182 to +186
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can have some docstrings and type hints here, that would be greatly appreciated. For instance, it's not immediately clear what **kwargs is until you read the source code.

if "onerror" in kwargs and kwargs["onerror"] is not None:
shutil.rmtree(*args, **kwargs)
return

Check warning on line 189 in src/quacc/runners/prep.py

View check run for this annotation

Codecov / codecov/patch

src/quacc/runners/prep.py#L188-L189

Added lines #L188 - L189 were not covered by tests

for i in range(max_retries):
try:
shutil.rmtree(*args, **kwargs)
return
except OSError as e:
if i == max_retries:
raise
Comment on lines +196 to +197
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we raise a specific exception and have a useful message?

if e.errno in {errno.ENOTEMPTY, errno.EBUSY}:
time.sleep(retry_wait)

Check warning on line 199 in src/quacc/runners/prep.py

View check run for this annotation

Codecov / codecov/patch

src/quacc/runners/prep.py#L195-L199

Added lines #L195 - L199 were not covered by tests
else:
raise

Check warning on line 201 in src/quacc/runners/prep.py

View check run for this annotation

Codecov / codecov/patch

src/quacc/runners/prep.py#L201

Added line #L201 was not covered by tests
Comment on lines +200 to +201
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with the exception to raise.

Loading