From a971fa9d584b35c35b675b65ed86faed77b46cf7 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 15 Apr 2015 10:25:43 +0100 Subject: [PATCH] Use try..finally in contextlib.contextmanager --- synapse/storage/util/id_generators.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/synapse/storage/util/id_generators.py b/synapse/storage/util/id_generators.py index 2e2a40898..e5dec1c94 100644 --- a/synapse/storage/util/id_generators.py +++ b/synapse/storage/util/id_generators.py @@ -97,9 +97,11 @@ class StreamIdGenerator(object): @contextlib.contextmanager def manager(): - yield next_id - with self._lock: - self._unfinished_ids.remove(next_id) + try: + yield next_id + finally: + with self._lock: + self._unfinished_ids.remove(next_id) return manager()