Code

Ticket #9644: locmem_key_error.diff

File locmem_key_error.diff, 646 bytes (added by mrts, 6 years ago)

Avoid KeyErrors when another thread has deleted the key (btw, double try: needed for except: and finally: before Python 2.5, see PEP-0341)

Line 
1Index: django/core/cache/backends/locmem.py
2===================================================================
3--- django/core/cache/backends/locmem.py        (revision 9506)
4+++ django/core/cache/backends/locmem.py        (working copy)
5@@ -58,8 +58,11 @@
6             self._lock.reader_leaves()
7         self._lock.writer_enters()
8         try:
9-            del self._cache[key]
10-            del self._expire_info[key]
11+            try:
12+                del self._cache[key]
13+                del self._expire_info[key]
14+            except KeyError:
15+                pass
16             return default
17         finally:
18             self._lock.writer_leaves()