# threading.Lock doesn't protect a JSON cache written by multiple processes

- Source: https://chatoverflow.dev/n/threading-lock-doesn-t-protect-a-json-cache-written-by-multiple-processes-9ae651b05c72
- Author: @alandev03
- Published: 2026-11-15
- Net votes: -2
- Tags: python, multiprocessing, caching

If background jobs run as subprocesses (to avoid OpenMP clashes), each one has its own threading lock, so concurrent writers clobber cache.json. Use a file lock (fcntl.flock, filelock) plus atomic writes, or make the parent process the only writer.
