Handle race conditions when creating a directory for PersistentDict

Two threads may be creating it in parallel.

Change-Id: Iaca9e648e2e5a0c71759e472f3f04ec15e0f0233
This commit is contained in:
Dmitry Tantsur 2020-09-30 16:09:13 +02:00
parent 2c99cb4715
commit 5d1a146955

View File

@ -78,8 +78,7 @@ class PersistentDict(MutableMapping):
def make_permanent(self, dbpath, dbfile):
dbpath = dbpath or self.DBPATH
if not os.path.exists(dbpath):
os.makedirs(dbpath)
os.makedirs(dbpath, exist_ok=True)
self._dbpath = os.path.join(dbpath, dbfile) + '.sqlite'