當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。