From d440972d100a66452c8c967500030d57717de4ee Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 12 Mar 2014 18:24:46 -0700 Subject: [PATCH] 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 --- taskflow/engines/worker_based/cache.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/taskflow/engines/worker_based/cache.py b/taskflow/engines/worker_based/cache.py index efacad09..de19095e 100644 --- a/taskflow/engines/worker_based/cache.py +++ b/taskflow/engines/worker_based/cache.py @@ -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)