Skip to content

Commit

Permalink
Merge pull request #235 from charles-cooper/fix/disk-cache-race
Browse files Browse the repository at this point in the history
fix race in disk cache
  • Loading branch information
charles-cooper authored May 28, 2024
2 parents 7b4854d + 108181d commit 0625410
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions boa/util/disk_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def caching_lookup(self, string, func):
return pickle.loads(f.read())
except OSError:
res = func()
tid = threading.get_ident()
tmp_p = p.with_suffix(f".{tid}.unfinished")
# use process ID and thread ID to avoid race conditions
job_id = f"{os.getpid()}.{threading.get_ident()}"
tmp_p = p.with_suffix(f".{job_id}.unfinished")
with tmp_p.open("wb") as f:
f.write(pickle.dumps(res))
# rename is atomic, don't really need to care about fsync
Expand Down

0 comments on commit 0625410

Please sign in to comment.