16
16
17
17
logger = logging .getLogger ('cache' )
18
18
19
+ LOCK_SUBDIR = 'locks'
19
20
20
21
acquired_count = {}
21
22
cachedir = None
@@ -40,7 +41,7 @@ def acquire_cache_lock(reason, cachefile):
40
41
setup_file (cachefile )
41
42
# TODO: is aqcuired_count even necessary? filelock.py seems to have similar logic inside.
42
43
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 } ) ' )
44
45
#assert 'EM_CACHE_IS_LOCKED' not in os.environ, f'attempt to lock the cache while a parent process is holding the lock ({reason})'
45
46
try :
46
47
cache_file_locks [cachefile ].acquire (60 )
@@ -49,7 +50,7 @@ def acquire_cache_lock(reason, cachefile):
49
50
cache_file_locks [cachefile ].acquire ()
50
51
51
52
#os.environ['EM_CACHE_IS_LOCKED'] = '1'
52
- logger .debug (' done' )
53
+ logger .debug (f'PID { os . getpid () } done' )
53
54
acquired_count [cachefile ] += 1
54
55
55
56
@@ -87,8 +88,10 @@ def ensure():
87
88
def erase ():
88
89
ensure_setup ()
89
90
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 )
92
95
93
96
94
97
def get_path (name ):
@@ -194,7 +197,7 @@ def setup_file(cache_file):
194
197
file_path = Path (cache_file )
195
198
assert not file_path .is_absolute ()
196
199
key_name = '_' .join (file_path .parts ) + '.lock'
197
- filename = Path (cachedir , 'locks' , key_name )
200
+ filename = Path (cachedir , LOCK_SUBDIR , key_name )
198
201
cache_file_locks [cache_file ] = filelock .FileLock (filename )
199
202
acquired_count [cache_file ] = 0
200
203
0 commit comments