Bases: object
A garbage collected container of semaphores.
This collection internally uses a weak value dictionary so that when a semaphore is no longer in use (by any threads) it will automatically be removed from this container by the garbage collector.
Gets (or creates) a semaphore with a given name.
Parameters: | name – The semaphore name to get/create (used to associate previously created names with the same semaphore). |
---|
Returns an newly constructed semaphore (or an existing one if it was already created for the given name).
Return the path used for external file-based locks.
Parameters: | conf (oslo_config.cfg.ConfigOpts) – Configuration object |
---|
Context based lock
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.
Parameters: |
|
---|
Remove an external lock file when it’s not used anymore This will be helpful when we have a lot of lock files
Set value for lock_path.
This can be used by tests to set lock_path to a temporary directory.
Synchronization decorator.
Decorating a method like so:
@synchronized('mylock')
def foo(self, *args):
...
ensures that only one thread will execute the foo method at a time.
Different methods can share the same lock:
@synchronized('mylock')
def foo(self, *args):
...
@synchronized('mylock')
def bar(self, *args):
...
This way only one of either foo or bar can be executing at a time.
Partial object generator for the synchronization decorator.
Redefine @synchronized in each project like so:
(in nova/utils.py)
from nova.openstack.common import lockutils
synchronized = lockutils.synchronized_with_prefix('nova-')
(in nova/foo.py)
from nova import utils
@utils.synchronized('mylock')
def bar(self, *args):
...
The lock_file_prefix argument is used to provide lock files on disk with a meaningful prefix.