Skip to content

Commit

Permalink
Fix #8: added lock around LRUCache.__getitem__
Browse files Browse the repository at this point in the history
  • Loading branch information
valtron committed Mar 1, 2013
1 parent 21a2010 commit 081692f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions jinja2/utils.py
Expand Up @@ -464,17 +464,21 @@ def __getitem__(self, key):
Raise a `KeyError` if it does not exist.
"""
rv = self._mapping[key]
if self._queue[-1] != key:
try:
self._remove(key)
except ValueError:
# if something removed the key from the container
# when we read, ignore the ValueError that we would
# get otherwise.
pass
self._append(key)
return rv
self._wlock.acquire()
try:
rv = self._mapping[key]
if self._queue[-1] != key:
try:
self._remove(key)
except ValueError:
# if something removed the key from the container
# when we read, ignore the ValueError that we would
# get otherwise.
pass
self._append(key)
return rv
finally:
self._wlock.release()

def __setitem__(self, key, value):
"""Sets the value for an item. Moves the item up so that it
Expand Down

0 comments on commit 081692f

Please sign in to comment.