Skip to content

Commit 91948f0

Browse files
committed
skip lock files in directory clean up
1 parent 2fbee2b commit 91948f0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pydra/utils/hash.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from collections.abc import Mapping
99
from functools import singledispatch
10-
from hashlib import blake2b
10+
from hashlib import blake2b, blake2s
1111
import logging
1212
from typing import (
1313
Dict,
@@ -135,7 +135,7 @@ def get_or_calculate_hash(self, key: CacheKey, calculate_hash: ty.Callable) -> H
135135
return self._hashes[key]
136136
except KeyError:
137137
pass
138-
key_path = self.location / blake2b(str(key).encode()).hexdigest()
138+
key_path = self.location / blake2s(str(key).encode()).hexdigest()
139139
with SoftFileLock(key_path.with_suffix(".lock")):
140140
if key_path.exists():
141141
return Hash(key_path.read_bytes())
@@ -147,6 +147,8 @@ def clean_up(self):
147147
"""Cleans up old hash caches that haven't been accessed in the last 30 days"""
148148
now = datetime.now()
149149
for path in self.location.iterdir():
150+
if path.endswith(".lock"):
151+
continue
150152
days = (now - datetime.fromtimestamp(path.lstat().st_atime)).days
151153
if days > self.cleanup_period:
152154
path.unlink()
@@ -198,10 +200,10 @@ def hash_object(
198200
Base Python types are implemented, including recursive lists and
199201
dicts. Custom types can be registered with :func:`register_serializer`.
200202
"""
201-
# try:
202-
return hash_single(obj, Cache(persistent=persistent_cache))
203-
# except Exception as e:
204-
# raise UnhashableError(f"Cannot hash object {obj!r} due to '{e}'") from e
203+
try:
204+
return hash_single(obj, Cache(persistent=persistent_cache))
205+
except Exception as e:
206+
raise UnhashableError(f"Cannot hash object {obj!r} due to '{e}'") from e
205207

206208

207209
def hash_single(obj: object, cache: Cache) -> Hash:

0 commit comments

Comments
 (0)