diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-07-16 15:11:38 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-07-16 15:11:38 +0000 |
| commit | 6dfe2e11702009f2fd8c495579501f529ee743cf (patch) | |
| tree | 7f1ac4e8f09970f2463a5e929b242321e41f55a1 /openstack/common | |
| parent | 0efb83409c32319321a61db9685ae1b029725c5a (diff) | |
| parent | 15c17fb1d04bf9fa3094e86fd7c38c4c8efad43c (diff) | |
| download | oslo-6dfe2e11702009f2fd8c495579501f529ee743cf.tar.gz oslo-6dfe2e11702009f2fd8c495579501f529ee743cf.tar.xz oslo-6dfe2e11702009f2fd8c495579501f529ee743cf.zip | |
Merge "Make lock_file_prefix optional"
Diffstat (limited to 'openstack/common')
| -rw-r--r-- | openstack/common/lockutils.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/openstack/common/lockutils.py b/openstack/common/lockutils.py index be362f8..ad8c0e5 100644 --- a/openstack/common/lockutils.py +++ b/openstack/common/lockutils.py @@ -135,7 +135,7 @@ else: _semaphores = weakref.WeakValueDictionary() -def synchronized(name, lock_file_prefix, external=False, lock_path=None): +def synchronized(name, lock_file_prefix=None, external=False, lock_path=None): """Synchronization decorator. Decorating a method like so:: @@ -159,8 +159,7 @@ def synchronized(name, lock_file_prefix, external=False, lock_path=None): This way only one of either foo or bar can be executing at a time. :param lock_file_prefix: The lock_file_prefix argument is used to provide - lock files on disk with a meaningful prefix. The prefix should end with a - hyphen ('-') if specified. + lock files on disk with a meaningful prefix. :param external: The external keyword argument denotes whether this lock should work across multiple processes. This means that if two different @@ -214,10 +213,17 @@ def synchronized(name, lock_file_prefix, external=False, lock_path=None): if not os.path.exists(local_lock_path): fileutils.ensure_tree(local_lock_path) + def add_prefix(name, prefix): + if not prefix: + return name + sep = '' if prefix.endswith('-') else '-' + return '%s%s%s' % (prefix, sep, name) + # NOTE(mikal): the lock name cannot contain directory # separators - safe_name = name.replace(os.sep, '_') - lock_file_name = '%s%s' % (lock_file_prefix, safe_name) + lock_file_name = add_prefix(name.replace(os.sep, '_'), + lock_file_prefix) + lock_file_path = os.path.join(local_lock_path, lock_file_name) @@ -273,7 +279,7 @@ def synchronized_with_prefix(lock_file_prefix): ... The lock_file_prefix argument is used to provide lock files on disk with a - meaningful prefix. The prefix should end with a hyphen ('-') if specified. + meaningful prefix. """ return functools.partial(synchronized, lock_file_prefix=lock_file_prefix) |
