Skip to content

Commit

Permalink
handle unpickling errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kavigupta committed Oct 2, 2024
1 parent 390330f commit 69c0a41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion permacache/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import shutil
import sys
from pickle import UnpicklingError

from appdirs import user_cache_dir

Expand Down Expand Up @@ -44,7 +46,14 @@ def __call__(self, *args, **kwargs):

with self.shelf as db:
if key in db:
return db[key]
try:
return db[key]
except UnpicklingError as e:
# total hack. not sure why this is happening
print(f"Unpickling error: {e}", file=sys.stderr)
print(repr(key), file=sys.stderr)
print("Deleting key", file=sys.stderr)
del db[key]
value = self._run_underlying(*args, **kwargs)
with self.shelf as db:
# TODO maybe check if key is now in db
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="permacache",
version="3.7.2",
version="3.7.3",
author="Kavi Gupta",
author_email="[email protected]",
description="Permanant cache.",
Expand Down

0 comments on commit 69c0a41

Please sign in to comment.