From 448ae9ca8dc7e68a63d9edb57a665a9aeed0a415 Mon Sep 17 00:00:00 2001 From: Gregory Williams Date: Tue, 14 May 2019 08:47:29 -0700 Subject: [PATCH] Add internal locking to bonobo.config.services.Exclusive. --- bonobo/config/services.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bonobo/config/services.py b/bonobo/config/services.py index 207d228..7478223 100644 --- a/bonobo/config/services.py +++ b/bonobo/config/services.py @@ -146,14 +146,19 @@ class Exclusive(ContextDecorator): """ _locks = {} + lock = threading.Lock() def __init__(self, wrapped): self._wrapped = wrapped def get_lock(self): _id = id(self._wrapped) - if not _id in Exclusive._locks: - Exclusive._locks[_id] = threading.RLock() + Exclusive.lock.acquire() + try: + if not _id in Exclusive._locks: + Exclusive._locks[_id] = threading.RLock() + finally: + Exclusive.lock.release() return Exclusive._locks[_id] def __enter__(self):