Skip to content

Commit

Permalink
Merge pull request #242 from QuantConnect/bug-240-handle-cache-invali…
Browse files Browse the repository at this point in the history
…d-state

Handle invalid storage file
  • Loading branch information
Martin-Molinero authored Dec 1, 2022
2 parents 8bbeae9 + e05f04a commit c41ff9e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lean/components/config/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ def __init__(self, file: str) -> None:
self.file = Path(file)

if self.file.exists():
content = self.file.read_text(encoding="utf-8")
if content:
self._data = loads(content)
else:
try:
content = self.file.read_text(encoding="utf-8")
if content:
self._data = loads(content)
else:
self._data = {}
except:
# Could happen rarely due to concurrency or unexpected failures, so if it does let's recover
self.file.unlink()
self._data = {}
else:
self._data = {}
Expand Down

0 comments on commit c41ff9e

Please sign in to comment.