Avoid calling callbacks while holding locks
Instead of calling the callback while holding a write lock (a recipe for deadlock) call the callbacks after we pop all the values to avoid any potential for deadlock. Change-Id: Idb4275d8f07d60e2ed83c0987b6c7354a09c8a71
This commit is contained in:
@@ -51,7 +51,8 @@ class Cache(object):
|
||||
with self._lock.write_lock():
|
||||
expired_values = [(k, v) for k, v in six.iteritems(self._data)
|
||||
if v.expired]
|
||||
for k, v in expired_values:
|
||||
if on_expired_callback:
|
||||
on_expired_callback(v)
|
||||
for (k, _v) in expired_values:
|
||||
self._data.pop(k, None)
|
||||
if on_expired_callback:
|
||||
for (_k, v) in expired_values:
|
||||
on_expired_callback(v)
|
||||
|
||||
Reference in New Issue
Block a user