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


Python reflection.get_callable_name方法代码示例

本文整理汇总了Python中oslo_utils.reflection.get_callable_name方法的典型用法代码示例。如果您正苦于以下问题:Python reflection.get_callable_name方法的具体用法?Python reflection.get_callable_name怎么用?Python reflection.get_callable_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oslo_utils.reflection的用法示例。


在下文中一共展示了reflection.get_callable_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def start(self, interval, initial_delay=None,
              stop_on_exception=True, timeout=0):
        start_time = time.time()

        def _idle_for(result, elapsed):
            delay = round(elapsed - interval, 2)
            if delay > 0:
                func_name = reflection.get_callable_name(self.f)
                LOG.warning('Function %(func_name)r run outlasted '
                            'interval by %(delay).2f sec',
                            {'func_name': func_name, 'delay': delay})
            elapsed_time = time.time() - start_time
            if timeout > 0 and elapsed_time > timeout:
                raise LoopingCallTimeOut(
                    _('Looping call timed out after %.02f seconds')
                    % elapsed_time)
            return -delay if delay < 0 else 0

        return self._start(_idle_for, initial_delay=initial_delay,
                           stop_on_exception=stop_on_exception) 
开发者ID:openstack,项目名称:oslo.service,代码行数:22,代码来源:loopingcall.py

示例2: __init__

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def __init__(self, volume_id):
        # Note here that the volume name is composed of the name of the class
        # along with the volume id that is being created, since a name of a
        # task uniquely identifies that task in storage it is important that
        # the name be relevant and identifiable if the task is recreated for
        # subsequent resumption (if applicable).
        #
        # UUIDs are *not* used as they can not be tied back to a previous tasks
        # state on resumption (since they are unique and will vary for each
        # task that is created). A name based off the volume id that is to be
        # created is more easily tied back to the original task so that the
        # volume create can be resumed/revert, and is much easier to use for
        # audit and tracking purposes.
        base_name = reflection.get_callable_name(self)
        super(VolumeCreator, self).__init__(name="%s-%s" % (base_name,
                                                            volume_id))
        self._volume_id = volume_id 
开发者ID:openstack,项目名称:taskflow,代码行数:19,代码来源:create_parallel_volume.py

示例3: backend_specific

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def backend_specific(*dialects):
    """Decorator to skip backend specific tests on inappropriate engines.

    ::dialects: list of dialects names under which the test will be launched.
    """
    def wrap(f):
        @functools.wraps(f)
        def ins_wrap(self):
            if not set(dialects).issubset(ALLOWED_DIALECTS):
                raise ValueError(
                    "Please use allowed dialects: %s" % ALLOWED_DIALECTS)
            if self.engine.name not in dialects:
                msg = ('The test "%s" can be run '
                       'only on %s. Current engine is %s.')
                args = (reflection.get_callable_name(f), ', '.join(dialects),
                        self.engine.name)
                self.skipTest(msg % args)
            else:
                return f(self)
        return ins_wrap
    return wrap 
开发者ID:openstack,项目名称:oslo.db,代码行数:23,代码来源:test_base.py

示例4: _synchronize

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def _synchronize(func, cls_name, rlock):
        def wrapper(*args, **kwargs):
            f_qual_name = reflection.get_callable_name(func)

            t_request = time.time()
            try:
                with rlock:
                    t_acquire = time.time()
                    LOG.debug("Method %(method_name)s acquired rlock. "
                              "Waited %(time_wait)0.3fs",
                              dict(method_name=f_qual_name,
                                   time_wait=t_acquire - t_request))
                    return func(*args, **kwargs)
            finally:
                t_release = time.time()
                LOG.debug("Method %(method_name)s released rlock. "
                          "Held %(time_held)0.3fs",
                          dict(method_name=f_qual_name,
                               time_held=t_release - t_acquire))
        return wrapper 
开发者ID:openstack,项目名称:os-win,代码行数:22,代码来源:baseutils.py

示例5: __call__

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def __call__(self, f):
        @six.wraps(f)
        def wrapper(*args, **kwargs):
            next_interval = self.retry_interval
            remaining = self.max_retries

            while True:
                try:
                    return f(*args, **kwargs)
                except Exception as e:
                    with excutils.save_and_reraise_exception() as ectxt:
                        if remaining > 0:
                            ectxt.reraise = not self._is_exception_expected(e)
                        else:
                            LOG.exception('Function exceeded '
                                          'retry limit.')
                    LOG.debug("Performing retry for function %s",
                              reflection.get_callable_name(f))
                    # NOTE(vsergeyev): We are using patched time module, so
                    #                  this effectively yields the execution
                    #                  context to another green thread.
                    time.sleep(next_interval)
                    if self.inc_retry_interval:
                        next_interval = min(
                            next_interval * 2,
                            self.max_retry_interval
                        )
                    remaining -= 1
        return wrapper 
开发者ID:openstack,项目名称:dragonflow,代码行数:31,代码来源:utils.py

示例6: _run_loop

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def _run_loop(self, idle_for_func,
                  initial_delay=None, stop_on_exception=True):
        kind = self._KIND
        func_name = reflection.get_callable_name(self.f)
        func = self.f if stop_on_exception else _safe_wrapper(self.f, kind,
                                                              func_name)
        if initial_delay:
            self._sleep(initial_delay)
        try:
            watch = timeutils.StopWatch()
            while self._running:
                watch.restart()
                result = func(*self.args, **self.kw)
                watch.stop()
                if not self._running:
                    break
                idle = idle_for_func(result, self._elapsed(watch))
                LOG.trace('%(kind)s %(func_name)r sleeping '
                          'for %(idle).02f seconds',
                          {'func_name': func_name, 'idle': idle,
                           'kind': kind})
                self._sleep(idle)
        except LoopingCallDone as e:
            self.done.send(e.retvalue)
        except Exception:
            exc_info = sys.exc_info()
            try:
                LOG.error('%(kind)s %(func_name)r failed',
                          {'kind': kind, 'func_name': func_name},
                          exc_info=exc_info)
                self.done.send_exception(*exc_info)
            finally:
                del exc_info
            return
        else:
            self.done.send(True) 
开发者ID:openstack,项目名称:oslo.service,代码行数:38,代码来源:loopingcall.py

示例7: _fetch_validate_factory

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def _fetch_validate_factory(flow_factory):
    if isinstance(flow_factory, six.string_types):
        factory_fun = _fetch_factory(flow_factory)
        factory_name = flow_factory
    else:
        factory_fun = flow_factory
        factory_name = reflection.get_callable_name(flow_factory)
        try:
            reimported = _fetch_factory(factory_name)
            assert reimported == factory_fun
        except (ImportError, AssertionError):
            raise ValueError('Flow factory %r is not reimportable by name %s'
                             % (factory_fun, factory_name))
    return (factory_name, factory_fun) 
开发者ID:openstack,项目名称:taskflow,代码行数:16,代码来源:helpers.py

示例8: _delayed_process

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def _delayed_process(self, func):
        """Runs the function using the instances executor (eventually).

        This adds a *nice* benefit on showing how long it took for the
        function to finally be executed from when the message was received
        to when it was finally ran (which can be a nice thing to know
        to determine bottle-necks...).
        """
        func_name = reflection.get_callable_name(func)

        def _on_run(watch, content, message):
            LOG.trace("It took %s seconds to get around to running"
                      " function/method '%s' with"
                      " message '%s'", watch.elapsed(), func_name,
                      ku.DelayedPretty(message))
            return func(content, message)

        def _on_receive(content, message):
            LOG.debug("Submitting message '%s' for execution in the"
                      " future to '%s'", ku.DelayedPretty(message), func_name)
            watch = timeutils.StopWatch()
            watch.start()
            try:
                self._executor.submit(_on_run, watch, content, message)
            except RuntimeError:
                LOG.error("Unable to continue processing message '%s',"
                          " submission to instance executor (with later"
                          " execution by '%s') was unsuccessful",
                          ku.DelayedPretty(message), func_name,
                          exc_info=True)

        return _on_receive 
开发者ID:openstack,项目名称:taskflow,代码行数:34,代码来源:server.py

示例9: __init__

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def __init__(self, execute, name=None, provides=None,
                 requires=None, auto_extract=True, rebind=None, revert=None,
                 version=None, inject=None):
        if not six.callable(execute):
            raise ValueError("Function to use for executing must be"
                             " callable")
        if revert is not None:
            if not six.callable(revert):
                raise ValueError("Function to use for reverting must"
                                 " be callable")
        if name is None:
            name = reflection.get_callable_name(execute)
        super(FunctorTask, self).__init__(name, provides=provides,
                                          inject=inject)
        self._execute = execute
        self._revert = revert
        if version is not None:
            self.version = version
        mapping = self._build_arg_mapping(execute, requires, rebind,
                                          auto_extract)
        self.rebind, exec_requires, self.optional = mapping

        if revert:
            revert_mapping = self._build_arg_mapping(revert, requires, rebind,
                                                     auto_extract)
        else:
            revert_mapping = (self.rebind, exec_requires, self.optional)
        (self.revert_rebind, revert_requires,
         self.revert_optional) = revert_mapping
        self.requires = exec_requires.union(revert_requires) 
开发者ID:openstack,项目名称:taskflow,代码行数:32,代码来源:task.py

示例10: _make_logger

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def _make_logger(self, level=logging.DEBUG):
        log = logging.getLogger(
            reflection.get_callable_name(self._get_test_method()))
        log.propagate = False
        for handler in reversed(log.handlers):
            log.removeHandler(handler)
        handler = test.CapturingLoggingHandler(level=level)
        log.addHandler(handler)
        log.setLevel(level)
        self.addCleanup(handler.reset)
        self.addCleanup(log.removeHandler, handler)
        return (log, handler) 
开发者ID:openstack,项目名称:taskflow,代码行数:14,代码来源:test_listeners.py

示例11: _periodics_watchdog

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def _periodics_watchdog(self, callable_, activity, spacing, exc_info,
                            traceback=None):
        LOG.exception("The periodic %(callable)s failed with: %(exception)s", {
            'exception': ''.join(traceback_mod.format_exception(*exc_info)),
            'callable': reflection.get_callable_name(callable_)}) 
开发者ID:openstack,项目名称:ironic-inspector,代码行数:7,代码来源:manager.py

示例12: triggers_fsm_error_transition

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def triggers_fsm_error_transition(errors=(Exception,),
                                  no_errors=(utils.NodeStateInvalidEvent,
                                             utils.NodeStateRaceCondition)):
    """Trigger an fsm error transition upon certain errors.

    It is assumed the first function arg of the decorated function is always a
    NodeInfo instance.

    :param errors: a tuple of exceptions upon which an error
                   event is triggered. Re-raised.
    :param no_errors: a tuple of exceptions that won't trigger the
                      error event.
    """
    def outer(func):
        @functools.wraps(func)
        def inner(node_info, *args, **kwargs):
            ret = None
            try:
                ret = func(node_info, *args, **kwargs)
            except no_errors as exc:
                LOG.debug('Not processing error event for the '
                          'exception: %(exc)s raised by %(func)s',
                          {'exc': exc,
                           'func': reflection.get_callable_name(func)},
                          node_info=node_info)
            except errors as exc:
                with excutils.save_and_reraise_exception():
                    LOG.error('Processing the error event because of an '
                              'exception %(exc_type)s: %(exc)s raised by '
                              '%(func)s',
                              {'exc_type': type(exc), 'exc': exc,
                               'func': reflection.get_callable_name(func)},
                              node_info=node_info)
                    # an error event should be possible from all states
                    node_info.finished(istate.Events.error, error=str(exc))
            return ret
        return inner
    return outer 
开发者ID:openstack,项目名称:ironic-inspector,代码行数:40,代码来源:node_cache.py

示例13: __call__

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def __call__(self, f):
        func_name = reflection.get_callable_name(f)

        def _func(*args, **kwargs):
            result = None
            try:
                if self._retry_count:
                    LOG.debug("Invoking %(func_name)s; retry count is "
                              "%(retry_count)d.",
                              {'func_name': func_name,
                               'retry_count': self._retry_count})
                result = f(*args, **kwargs)
            except self._exceptions:
                with excutils.save_and_reraise_exception() as ctxt:
                    LOG.warning("Exception which is in the suggested list "
                                "of exceptions occurred while invoking "
                                "function: %s.",
                                func_name,
                                exc_info=True)
                    if (self._max_retry_count != -1 and
                            self._retry_count >= self._max_retry_count):
                        LOG.error("Cannot retry upon suggested exception "
                                  "since retry count (%(retry_count)d) "
                                  "reached max retry count "
                                  "(%(max_retry_count)d).",
                                  {'retry_count': self._retry_count,
                                   'max_retry_count': self._max_retry_count})
                    else:
                        ctxt.reraise = False
                        self._retry_count += 1
                        self._sleep_time += self._inc_sleep_time
                        return self._sleep_time
            raise loopingcall.LoopingCallDone(result)

        def func(*args, **kwargs):
            loop = loopingcall.DynamicLoopingCall(_func, *args, **kwargs)
            evt = loop.start(periodic_interval_max=self._max_sleep_time)
            return evt.wait()

        return func 
开发者ID:openstack,项目名称:oslo.vmware,代码行数:42,代码来源:api.py

示例14: test_mere_function

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def test_mere_function(self):
        name = reflection.get_callable_name(mere_function)
        self.assertEqual('.'.join((__name__, 'mere_function')), name) 
开发者ID:openstack,项目名称:oslo.utils,代码行数:5,代码来源:test_reflection.py

示例15: test_method

# 需要导入模块: from oslo_utils import reflection [as 别名]
# 或者: from oslo_utils.reflection import get_callable_name [as 别名]
def test_method(self):
        name = reflection.get_callable_name(Class.method)
        self.assertEqual('.'.join((__name__, 'Class', 'method')), name) 
开发者ID:openstack,项目名称:oslo.utils,代码行数:5,代码来源:test_reflection.py


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