Skip to content

Commit

Permalink
reg: make sure temporary directory is created
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Apr 17, 2024
1 parent bad2ccd commit 70f811e
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions mpl_data_cast/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self,
dir=pathlib.Path(tempfile.gettempdir()) / "MPL-Data-Cast"
)
)
self.tempdir.mkdir(exist_ok=True, parents=True)
# Make sure everything is removed in the end.
atexit.register(shutil.rmtree, self.tempdir, ignore_errors=True)

Expand Down Expand Up @@ -280,21 +281,22 @@ def cleanup_tmp_dirs():
# New versions of MPL-Data-Cast, we have this temporary directory for
# recipes:
temp_dir = pathlib.Path(tempfile.gettempdir()) / "MPL-Data-Cast"
for pp in temp_dir.glob("PID-*"):
print(pp)
try:
if pp.is_dir():
# Every subdirectory is named according to PID of its process.
# If the process does not exist anymore, we may delete it.
pid = int(pp.name.split("-")[1])
print(pp, pid, psutil.pid_exists(pid))
if not psutil.pid_exists(pid):
shutil.rmtree(pp, ignore_errors=True)
except BaseException:
logger.warning(
f"Could not remove stale data {pp} from PID {pid}:\n"
f"{traceback.format_exc()}"
)
if temp_dir.is_dir():
for pp in temp_dir.glob("PID-*"):
try:
if pp.is_dir():
# Every subdirectory is named according to PID of its
# process. If the process does not exist anymore, we
# may delete it.
pid = int(pp.name.split("-")[1])
print(pp, pid, psutil.pid_exists(pid))
if not psutil.pid_exists(pid):
shutil.rmtree(pp, ignore_errors=True)
except BaseException:
logger.warning(
f"Could not remove stale data {pp} from PID {pid}:\n"
f"{traceback.format_exc()}"
)


def get_available_recipe_names() -> list[str]:
Expand Down

0 comments on commit 70f811e

Please sign in to comment.