Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle unpickling errors #5

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading