Skip to content

Commit bed35e6

Browse files
committed
Fix cache clearing (correctly preserve the lock directory)
1 parent 2b2d617 commit bed35e6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tools/cache.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
logger = logging.getLogger('cache')
1818

19+
LOCK_SUBDIR = 'locks'
1920

2021
acquired_count = {}
2122
cachedir = None
@@ -40,7 +41,7 @@ def acquire_cache_lock(reason, cachefile):
4041
setup_file(cachefile)
4142
# TODO: is aqcuired_count even necessary? filelock.py seems to have similar logic inside.
4243
if acquired_count[cachefile] == 0:
43-
logger.debug(f'PID {os.getpid()} acquiring multiprocess file lock to {cache_file_locks[cachefile].lock_file} for {cachefile}')
44+
logger.debug(f'PID {os.getpid()} acquiring multiprocess file lock {cache_file_locks[cachefile].lock_file} for {cachefile} ({reason})')
4445
#assert 'EM_CACHE_IS_LOCKED' not in os.environ, f'attempt to lock the cache while a parent process is holding the lock ({reason})'
4546
try:
4647
cache_file_locks[cachefile].acquire(60)
@@ -49,7 +50,7 @@ def acquire_cache_lock(reason, cachefile):
4950
cache_file_locks[cachefile].acquire()
5051

5152
#os.environ['EM_CACHE_IS_LOCKED'] = '1'
52-
logger.debug('done')
53+
logger.debug(f'PID {os.getpid()} done')
5354
acquired_count[cachefile] += 1
5455

5556

@@ -87,8 +88,10 @@ def ensure():
8788
def erase():
8889
ensure_setup()
8990
with lock('erase', global_cachelock):
90-
# Delete everything except the lockfile itself
91-
utils.delete_contents(cachedir, exclude=[os.path.basename(global_cachelock)])
91+
# Delete everything except the lockfiles directory itself
92+
utils.delete_contents(cachedir, exclude=[LOCK_SUBDIR])
93+
assert os.path.exists(Path(cachedir, LOCK_SUBDIR))
94+
assert os.path.exists(cache_file_locks[global_cachelock].lock_file)
9295

9396

9497
def get_path(name):
@@ -194,7 +197,7 @@ def setup_file(cache_file):
194197
file_path = Path(cache_file)
195198
assert not file_path.is_absolute()
196199
key_name = '_'.join(file_path.parts) + '.lock'
197-
filename = Path(cachedir, 'locks', key_name)
200+
filename = Path(cachedir, LOCK_SUBDIR, key_name)
198201
cache_file_locks[cache_file] = filelock.FileLock(filename)
199202
acquired_count[cache_file] = 0
200203

0 commit comments

Comments
 (0)