Reduce file lock time

This commit is contained in:
Kovid Goyal 2019-03-16 11:09:23 +05:30
parent 138a0338f7
commit 8921bb8324
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -219,17 +219,17 @@ class DynamicConfig(dict):
d = {} d = {}
if os.path.exists(self.file_path): if os.path.exists(self.file_path):
with ExclusiveFile(self.file_path) as f: with ExclusiveFile(self.file_path) as f:
raw = f.read() raw = f.read().strip()
try: try:
d = cPickle.loads(raw) if raw.strip() else {} d = cPickle.loads(raw) if raw else {}
except SystemError: except SystemError:
pass pass
except Exception: except Exception:
print('WARNING: Failed to unpickle stored config object, ignoring') print('WARNING: Failed to unpickle stored config object, ignoring')
if DEBUG: if DEBUG:
import traceback import traceback
traceback.print_exc() traceback.print_exc()
d = {} d = {}
if clear_current: if clear_current:
self.clear() self.clear()
self.update(d) self.update(d)