Python oslo_concurrency.lockutils.synchronized() Examples
The following are 15
code examples of oslo_concurrency.lockutils.synchronized().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
oslo_concurrency.lockutils
, or try the search function
.
Example #1
Source File: server.py From vdi-broker with Apache License 2.0 | 5 votes |
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
Example #2
Source File: server.py From vdi-broker with Apache License 2.0 | 5 votes |
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
Example #3
Source File: common.py From searchlight with Apache License 2.0 | 5 votes |
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
Example #4
Source File: test_lockutils.py From oslo.concurrency with Apache License 2.0 | 5 votes |
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")
Example #5
Source File: test_lockutils.py From oslo.concurrency with Apache License 2.0 | 5 votes |
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())
Example #6
Source File: test_lockutils.py From oslo.concurrency with Apache License 2.0 | 5 votes |
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()
Example #7
Source File: test_lockutils.py From oslo.concurrency with Apache License 2.0 | 5 votes |
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()
Example #8
Source File: test_lockutils.py From oslo.concurrency with Apache License 2.0 | 5 votes |
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()
Example #9
Source File: server.py From coriolis with GNU Affero General Public License v3.0 | 5 votes |
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
Example #10
Source File: server.py From coriolis with GNU Affero General Public License v3.0 | 5 votes |
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
Example #11
Source File: server.py From coriolis with GNU Affero General Public License v3.0 | 5 votes |
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
Example #12
Source File: server.py From coriolis with GNU Affero General Public License v3.0 | 5 votes |
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
Example #13
Source File: server.py From coriolis with GNU Affero General Public License v3.0 | 5 votes |
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
Example #14
Source File: server.py From coriolis with GNU Affero General Public License v3.0 | 5 votes |
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
Example #15
Source File: iscsi.py From nova-powervm with Apache License 2.0 | 4 votes |
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