diff options
author | Davanum Srinivas <dims@linux.vnet.ibm.com> | 2013-10-16 12:07:10 -0400 |
---|---|---|
committer | Davanum Srinivas <dims@linux.vnet.ibm.com> | 2013-10-22 07:27:45 -0400 |
commit | a0bcd7b90c38b104cb278223679cedf5cc11c74c (patch) | |
tree | 1a1bc34dc80749eeda86a77f5e4e4881b1a0fd4e | |
parent | c29d4509031d5d5d5421a92d075afc2620da5244 (diff) | |
download | nova-a0bcd7b90c38b104cb278223679cedf5cc11c74c.tar.gz |
Sync lockutils from oslo
d498c42 Fix to properly log when we release a semaphore...
3e3ac0c Modify lockutils.py due to dispose of eventlet...
Change-Id: I2786527cba16cb4cd94999927e9d7aed2ed99357
Related-Bug: #1235437
-rw-r--r-- | nova/openstack/common/lockutils.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/nova/openstack/common/lockutils.py b/nova/openstack/common/lockutils.py index 7d69f488d7..b53a828391 100644 --- a/nova/openstack/common/lockutils.py +++ b/nova/openstack/common/lockutils.py @@ -20,10 +20,10 @@ import contextlib import errno import functools import os +import threading import time import weakref -from eventlet import semaphore from oslo.config import cfg from nova.openstack.common import fileutils @@ -137,7 +137,8 @@ _semaphores = weakref.WeakValueDictionary() def lock(name, lock_file_prefix=None, external=False, lock_path=None): """Context based lock - This function yields a `semaphore.Semaphore` instance unless external is + This function yields a `threading.Semaphore` instance (if we don't use + eventlet.monkey_patch(), else `semaphore.Semaphore`) unless external is True, in which case, it'll yield an InterProcessLock instance. :param lock_file_prefix: The lock_file_prefix argument is used to provide @@ -155,7 +156,7 @@ def lock(name, lock_file_prefix=None, external=False, lock_path=None): # NOTE(soren): If we ever go natively threaded, this will be racy. # See http://stackoverflow.com/questions/5390569/dyn # amically-allocating-and-destroying-mutexes - sem = _semaphores.get(name, semaphore.Semaphore()) + sem = _semaphores.get(name, threading.Semaphore()) if name not in _semaphores: # this check is not racy - we're already holding ref locally # so GC won't remove the item and there was no IO switch @@ -240,13 +241,14 @@ def synchronized(name, lock_file_prefix=None, external=False, lock_path=None): def wrap(f): @functools.wraps(f) def inner(*args, **kwargs): - with lock(name, lock_file_prefix, external, lock_path): - LOG.debug(_('Got semaphore / lock "%(function)s"'), + try: + with lock(name, lock_file_prefix, external, lock_path): + LOG.debug(_('Got semaphore / lock "%(function)s"'), + {'function': f.__name__}) + return f(*args, **kwargs) + finally: + LOG.debug(_('Semaphore / lock released "%(function)s"'), {'function': f.__name__}) - return f(*args, **kwargs) - - LOG.debug(_('Semaphore / lock released "%(function)s"'), - {'function': f.__name__}) return inner return wrap |