本文整理汇总了Python中oslo_concurrency.lockutils.synchronized_with_prefix方法的典型用法代码示例。如果您正苦于以下问题:Python lockutils.synchronized_with_prefix方法的具体用法?Python lockutils.synchronized_with_prefix怎么用?Python lockutils.synchronized_with_prefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_concurrency.lockutils
的用法示例。
在下文中一共展示了lockutils.synchronized_with_prefix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_synchronized_with_prefix
# 需要导入模块: from oslo_concurrency import lockutils [as 别名]
# 或者: from oslo_concurrency.lockutils import synchronized_with_prefix [as 别名]
def test_synchronized_with_prefix(self):
lock_name = 'mylock'
lock_pfix = 'mypfix-'
foo = lockutils.synchronized_with_prefix(lock_pfix)
@foo(lock_name, external=True)
def bar(dirpath, pfix, name):
return True
lock_dir = tempfile.mkdtemp()
self.config(lock_path=lock_dir, group='oslo_concurrency')
self.assertTrue(bar(lock_dir, lock_pfix, lock_name))
示例2: synchronized_with_prefix
# 需要导入模块: from oslo_concurrency import lockutils [as 别名]
# 或者: from oslo_concurrency.lockutils import synchronized_with_prefix [as 别名]
def synchronized_with_prefix(lock_file_prefix):
"""Partial object generator for the synchronization decorator.
Redefine @synchronized in each project like so::
(in nova/utils.py)
from oslo_concurrency import lockutils
_prefix = 'nova'
synchronized = lockutils.synchronized_with_prefix(_prefix)
lock_cleanup = lockutils.remove_external_lock_file_with_prefix(_prefix)
(in nova/foo.py)
from nova import utils
@utils.synchronized('mylock')
def bar(self, *args):
...
Eventually clean up with::
lock_cleanup('mylock')
:param lock_file_prefix: A string used to provide lock files on disk with a
meaningful prefix. Will be separated from the lock name with a hyphen,
which may optionally be included in the lock_file_prefix (e.g.
``'nova'`` and ``'nova-'`` are equivalent).
"""
return functools.partial(synchronized, lock_file_prefix=lock_file_prefix)
示例3: remove_external_lock_file_with_prefix
# 需要导入模块: from oslo_concurrency import lockutils [as 别名]
# 或者: from oslo_concurrency.lockutils import synchronized_with_prefix [as 别名]
def remove_external_lock_file_with_prefix(lock_file_prefix):
"""Partial object generator for the remove lock file function.
Redefine remove_external_lock_file_with_prefix in each project like so::
(in nova/utils.py)
from oslo_concurrency import lockutils
_prefix = 'nova'
synchronized = lockutils.synchronized_with_prefix(_prefix)
lock = lockutils.lock_with_prefix(_prefix)
lock_cleanup = lockutils.remove_external_lock_file_with_prefix(_prefix)
(in nova/foo.py)
from nova import utils
@utils.synchronized('mylock')
def bar(self, *args):
...
def baz(self, *args):
...
with utils.lock('mylock'):
...
...
<eventually call lock_cleanup('mylock') to clean up>
The lock_file_prefix argument is used to provide lock files on disk with a
meaningful prefix.
"""
return functools.partial(remove_external_lock_file,
lock_file_prefix=lock_file_prefix)