当前位置: 首页>>代码示例>>Python>>正文


Python lockutils.synchronized_with_prefix方法代码示例

本文整理汇总了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)) 
开发者ID:openstack,项目名称:oslo.concurrency,代码行数:16,代码来源:test_lockutils.py

示例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) 
开发者ID:openstack,项目名称:oslo.concurrency,代码行数:33,代码来源:lockutils.py

示例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) 
开发者ID:openstack,项目名称:oslo.concurrency,代码行数:35,代码来源:lockutils.py


注:本文中的oslo_concurrency.lockutils.synchronized_with_prefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。