From 69c0a4140e74328ff1d8abe343debba59e592a10 Mon Sep 17 00:00:00 2001 From: Kavi Gupta Date: Wed, 2 Oct 2024 12:36:37 -0700 Subject: [PATCH] handle unpickling errors --- permacache/cache.py | 11 ++++++++++- setup.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/permacache/cache.py b/permacache/cache.py index ff3a8b8..320ef87 100644 --- a/permacache/cache.py +++ b/permacache/cache.py @@ -1,5 +1,7 @@ import os import shutil +import sys +from pickle import UnpicklingError from appdirs import user_cache_dir @@ -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 diff --git a/setup.py b/setup.py index 33f336e..79df7ee 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="permacache", - version="3.7.2", + version="3.7.3", author="Kavi Gupta", author_email="permacache@kavigupta.org", description="Permanant cache.",