botocore
botocore copied to clipboard
fix: resolve potential race condition in JSONFileCache
The JSONFileCache.__setitems__
might raise a FileExistsError
if it is
run in parallel by two threads / processes:
- Both processes discover the working dir hasn't been created yet.
- The first process creates the working dir.
- The second process tries to create the working dir, too and fails as it already exists.
Accept this potential race — exist_ok=True
will prevent os.makedirs
to raise an exception.
The os.path.isdir
condition is technically no longer needed but kept
keeping the change small. Furthermore, it should be slightly faster
as the cache should exist most of the time.
The exist_ok
parameter is supported since Python 3.2 / fixed in 3.4.1
and therefore available in all needed python versions.