Skip to content
Merged
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
25 changes: 24 additions & 1 deletion cadetrdm/tools/process_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,32 @@
from abc import abstractmethod
from pathlib import Path
import subprocess
import stat
import time

from cadetrdm import ProjectRepo, Options
from cadetrdm.wrapper import tracks_results


def _on_rm_error(func, path, exc_info):
try:
os.chmod(path, stat.S_IWRITE)
except Exception:
pass
func(path)

def rmtree_with_retries(path: Path, retries: int = 8, sleep_s: float = 0.25):
last_err = None
for _ in range(retries):
try:
shutil.rmtree(path, onerror=_on_rm_error)
return
except PermissionError as e:
last_err = e
time.sleep(sleep_s)
raise last_err


class ParallelizationBase:
def __init__(self, n_cores=1):
self.n_cores = n_cores
Expand Down Expand Up @@ -136,7 +157,9 @@ def create_output(root_path: Path, output_path: Path, n_cores=1):
None
"""
if os.path.exists(output_path):
shutil.rmtree(output_path)
rmtree_with_retries(output_path)


shutil.copytree(root_path, output_path)

# Find all myst files recursively
Expand Down