From 3c582112c056aaaab31db845c74a15bb0d1339b2 Mon Sep 17 00:00:00 2001 From: Willem de Groot Date: Tue, 15 Mar 2016 15:10:48 +0100 Subject: [PATCH] Fix expiration bug with Python 3.5 --- expiringdict/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/expiringdict/__init__.py b/expiringdict/__init__.py index 3e2f298..037250b 100644 --- a/expiringdict/__init__.py +++ b/expiringdict/__init__.py @@ -69,7 +69,12 @@ def __setitem__(self, key, value): """ Set d[key] to value. """ with self.lock: if len(self) == self.max_len: - self.popitem(last=False) + try: + self.popitem(last=False) + except KeyError: + # cache was full, but not anymore because + # old items got purged during popitem() + pass OrderedDict.__setitem__(self, key, (value, time.time())) def pop(self, key, default=None):