From a6473f19eed61bc41aadfbd8c0adcccc4b091e3e Mon Sep 17 00:00:00 2001 From: Gregory Williams Date: Wed, 15 May 2019 08:27:20 -0700 Subject: [PATCH] Rename lock variable, and use it as a context manager. --- bonobo/config/services.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bonobo/config/services.py b/bonobo/config/services.py index 7478223..4cc0049 100644 --- a/bonobo/config/services.py +++ b/bonobo/config/services.py @@ -146,19 +146,16 @@ class Exclusive(ContextDecorator): """ _locks = {} - lock = threading.Lock() + _locks_creation_lock = threading.Lock() def __init__(self, wrapped): self._wrapped = wrapped def get_lock(self): _id = id(self._wrapped) - Exclusive.lock.acquire() - try: + with Exclusive._locks_creation_lock: if not _id in Exclusive._locks: Exclusive._locks[_id] = threading.RLock() - finally: - Exclusive.lock.release() return Exclusive._locks[_id] def __enter__(self):