I think the LRUCache class in Jinja2 has a bug. The problem is that the "getitem" method may mutate the cache, but that method does not acquire the write lock, "_wlock".
For example, here's one scenario:
In my project I've seen the "setitem" method raise a KeyError. I assume that there's a similar execution scenario behind those exceptions, but I could be wrong.
In any case, I think "getitem" clearly needs to acquire "_wlock" before it removes and appends keys.
[Markdown messed up my report. Let me try again.]
To add to this 2 year old ticket... I have also observed the same exception in my system.
[Tue Feb 12 19:48:16 2013] [error] File "/local/python_envs/www/local/lib/python2.7/site-packages/jinja2/utils.py", line 473, in __setitem__
[Tue Feb 12 19:48:16 2013] [error] del self._mapping[self._popleft()]
[Tue Feb 12 19:48:16 2013] [error] KeyError: '_breadcrumbs.html
Pessimistic locking for LRU cache. This fixes #8