Thread safe method to create directory for db

This commit is contained in:
shortcutme 2019-12-17 15:02:18 +01:00
parent 9b1f6337c3
commit 98c98fbac7
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 4 additions and 1 deletions

View File

@ -108,9 +108,12 @@ class Db(object):
if self not in opened_dbs:
opened_dbs.append(self)
s = time.time()
if not os.path.isdir(self.db_dir): # Directory not exist yet
try: # Directory not exist yet
os.makedirs(self.db_dir)
self.log.debug("Created Db path: %s" % self.db_dir)
except OSError as err:
if err.errno != errno.EEXIST:
raise err
if not os.path.isfile(self.db_path):
self.log.debug("Db file not exist yet: %s" % self.db_path)
self.conn = sqlite3.connect(self.db_path, isolation_level="DEFERRED", check_same_thread=False)