'Acquire a lock and release it only if there is an exception.
The release method still needs to be scheduled to be run at the
end of the thread using the Thread.link method.
:param retry: When True, retry if lock was released while stealing.
:type retry: boolean'

@contextlib.contextmanager
def thread_lock(self, retry=True):

    try:
        self.acquire(retry)
        (yield)
    except exception.ActionInProgress:
        raise
    except:
        with excutils.save_and_reraise_exception():
            self.release()
