當前位置: 首頁>>代碼示例>>Python>>正文


Python lockutils.synchronized方法代碼示例

本文整理匯總了Python中oslo_concurrency.lockutils.synchronized方法的典型用法代碼示例。如果您正苦於以下問題:Python lockutils.synchronized方法的具體用法?Python lockutils.synchronized怎麽用?Python lockutils.synchronized使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oslo_concurrency.lockutils的用法示例。


在下文中一共展示了lockutils.synchronized方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: application_synchronized

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def application_synchronized(func):
    @functools.wraps(func)
    def wrapper(self, ctxt, application_id, *args, **kwargs):
        @lockutils.synchronized(application_id)
        def inner():
            return func(self, ctxt, application_id, *args, **kwargs)
        return inner()
    return wrapper 
開發者ID:cloudbase,項目名稱:vdi-broker,代碼行數:10,代碼來源:server.py

示例2: remote_session_synchronized

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def remote_session_synchronized(func):
    @functools.wraps(func)
    def wrapper(self, ctxt, session_id, *args, **kwargs):
        @lockutils.synchronized(session_id)
        def inner():
            return func(self, ctxt, session_id, *args, **kwargs)
        return inner()
    return wrapper 
開發者ID:cloudbase,項目名稱:vdi-broker,代碼行數:10,代碼來源:server.py

示例3: memoize

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def memoize(lock_name):
    def memoizer_wrapper(func):
        @lockutils.synchronized(lock_name)
        def memoizer(lock_name):
            if lock_name not in _CACHED_THREAD_POOL:
                _CACHED_THREAD_POOL[lock_name] = func()

            return _CACHED_THREAD_POOL[lock_name]

        return memoizer(lock_name)

    return memoizer_wrapper 
開發者ID:openstack,項目名稱:searchlight,代碼行數:14,代碼來源:common.py

示例4: test_synchronized_wrapped_function_metadata

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def test_synchronized_wrapped_function_metadata(self):
        @lockutils.synchronized('whatever', 'test-')
        def foo():
            """Bar."""
            pass

        self.assertEqual('Bar.', foo.__doc__, "Wrapped function's docstring "
                                              "got lost")
        self.assertEqual('foo', foo.__name__, "Wrapped function's name "
                                              "got mangled") 
開發者ID:openstack,項目名稱:oslo.concurrency,代碼行數:12,代碼來源:test_lockutils.py

示例5: test_nested_synchronized_external_works

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def test_nested_synchronized_external_works(self):
        """We can nest external syncs."""
        self.config(lock_path=tempfile.mkdtemp(), group='oslo_concurrency')
        sentinel = object()

        @lockutils.synchronized('testlock1', 'test-', external=True)
        def outer_lock():

            @lockutils.synchronized('testlock2', 'test-', external=True)
            def inner_lock():
                return sentinel
            return inner_lock()

        self.assertEqual(sentinel, outer_lock()) 
開發者ID:openstack,項目名稱:oslo.concurrency,代碼行數:16,代碼來源:test_lockutils.py

示例6: test_synchronized_without_prefix

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def test_synchronized_without_prefix(self):
        self.config(lock_path=tempfile.mkdtemp(), group='oslo_concurrency')

        @lockutils.synchronized('lock', external=True)
        def test_without_prefix():
            # We can't check much
            pass

        test_without_prefix() 
開發者ID:openstack,項目名稱:oslo.concurrency,代碼行數:11,代碼來源:test_lockutils.py

示例7: test_synchronized_prefix_without_hypen

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def test_synchronized_prefix_without_hypen(self):
        self.config(lock_path=tempfile.mkdtemp(), group='oslo_concurrency')

        @lockutils.synchronized('lock', 'hypen', True)
        def test_without_hypen():
            # We can't check much
            pass

        test_without_hypen() 
開發者ID:openstack,項目名稱:oslo.concurrency,代碼行數:11,代碼來源:test_lockutils.py

示例8: test_lock_file_exists

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def test_lock_file_exists(self):
        lock_file = os.path.join(self.lock_dir, 'lock-file')

        @lockutils.synchronized('lock-file', external=True,
                                lock_path=self.lock_dir)
        def foo():
            self.assertTrue(os.path.exists(lock_file))

        foo() 
開發者ID:openstack,項目名稱:oslo.concurrency,代碼行數:11,代碼來源:test_lockutils.py

示例9: endpoint_synchronized

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def endpoint_synchronized(func):
    @functools.wraps(func)
    def wrapper(self, ctxt, endpoint_id, *args, **kwargs):
        @lockutils.synchronized(
            constants.ENDPOINT_LOCK_NAME_FORMAT % endpoint_id,
            external=True)
        def inner():
            return func(self, ctxt, endpoint_id, *args, **kwargs)
        return inner()
    return wrapper 
開發者ID:cloudbase,項目名稱:coriolis,代碼行數:12,代碼來源:server.py

示例10: replica_synchronized

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def replica_synchronized(func):
    @functools.wraps(func)
    def wrapper(self, ctxt, replica_id, *args, **kwargs):
        @lockutils.synchronized(
            constants.REPLICA_LOCK_NAME_FORMAT % replica_id,
            external=True)
        def inner():
            return func(self, ctxt, replica_id, *args, **kwargs)
        return inner()
    return wrapper 
開發者ID:cloudbase,項目名稱:coriolis,代碼行數:12,代碼來源:server.py

示例11: schedule_synchronized

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def schedule_synchronized(func):
    @functools.wraps(func)
    def wrapper(self, ctxt, replica_id, schedule_id, *args, **kwargs):
        @lockutils.synchronized(
            constants.SCHEDULE_LOCK_NAME_FORMAT % schedule_id,
            external=True)
        def inner():
            return func(self, ctxt, replica_id, schedule_id, *args, **kwargs)
        return inner()
    return wrapper 
開發者ID:cloudbase,項目名稱:coriolis,代碼行數:12,代碼來源:server.py

示例12: task_synchronized

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def task_synchronized(func):
    @functools.wraps(func)
    def wrapper(self, ctxt, task_id, *args, **kwargs):
        @lockutils.synchronized(
            constants.TASK_LOCK_NAME_FORMAT % task_id,
            external=True)
        def inner():
            return func(self, ctxt, task_id, *args, **kwargs)
        return inner()
    return wrapper 
開發者ID:cloudbase,項目名稱:coriolis,代碼行數:12,代碼來源:server.py

示例13: parent_tasks_execution_synchronized

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def parent_tasks_execution_synchronized(func):
    @functools.wraps(func)
    def wrapper(self, ctxt, task_id, *args, **kwargs):
        task = db_api.get_task(ctxt, task_id)
        @lockutils.synchronized(
            constants.EXECUTION_LOCK_NAME_FORMAT % task.execution_id,
            external=True)
        @lockutils.synchronized(
            constants.TASK_LOCK_NAME_FORMAT % task_id,
            external=True)
        def inner():
            return func(self, ctxt, task_id, *args, **kwargs)
        return inner()
    return wrapper 
開發者ID:cloudbase,項目名稱:coriolis,代碼行數:16,代碼來源:server.py

示例14: tasks_execution_synchronized

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def tasks_execution_synchronized(func):
    @functools.wraps(func)
    def wrapper(self, ctxt, replica_id, execution_id, *args, **kwargs):
        @lockutils.synchronized(
            constants.EXECUTION_LOCK_NAME_FORMAT % execution_id,
            external=True)
        def inner():
            return func(self, ctxt, replica_id, execution_id, *args, **kwargs)
        return inner()
    return wrapper 
開發者ID:cloudbase,項目名稱:coriolis,代碼行數:12,代碼來源:server.py

示例15: get_iscsi_initiators

# 需要導入模塊: from oslo_concurrency import lockutils [as 別名]
# 或者: from oslo_concurrency.lockutils import synchronized [as 別名]
def get_iscsi_initiators(adapter, vios_ids=None):
    """Gets the VIOS iSCSI initiators.

     For the first time invocation of this method after process start up,
     it populates initiators data for VIOSes (if specified, otherwise it
     gets active VIOSes from the host) and stores in memory for futher
     lookup.

    :param adapter: The pypowervm adapter
    :param vios_ids: List of VIOS ids to get the initiators. If not
                     specified, a list of active VIOSes for the
                     host is fetched (but only for the first time)
                     through the pypowervm adapter.
    :return: A dict of the form
             {<vios_id>: <list of initiators>}
    """

    global _ISCSI_INITIATORS

    def discover_initiator(vios_id):

        # Get the VIOS id lock for initiator lookup
        @lockutils.synchronized('inititator-lookup-' + vios_id)
        def _discover_initiator():
            if vios_id in _ISCSI_INITIATORS and _ISCSI_INITIATORS[vios_id]:
                return
            else:
                try:
                    initiator = hdisk.discover_iscsi_initiator(
                        adapter, vios_id)
                    _ISCSI_INITIATORS[vios_id] = initiator
                except (pvm_exc.ISCSIDiscoveryFailed,
                        pvm_exc.JobRequestFailed) as e:
                    # TODO(chhagarw): handle differently based on
                    # error codes
                    LOG.error(e)

        _discover_initiator()

    if vios_ids is None and not _ISCSI_INITIATORS:
        vios_list = pvm_partition.get_active_vioses(adapter)
        vios_ids = [vios.uuid for vios in vios_list]

    for vios_id in vios_ids or []:
        discover_initiator(vios_id)

    LOG.debug("iSCSI initiator info: %s" % _ISCSI_INITIATORS)
    return _ISCSI_INITIATORS 
開發者ID:openstack,項目名稱:nova-powervm,代碼行數:50,代碼來源:iscsi.py


注:本文中的oslo_concurrency.lockutils.synchronized方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。