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


Python greenthread.sleep方法代码示例

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


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

示例1: _ssh_execute

# 需要导入模块: from eventlet import greenthread [as 别名]
# 或者: from eventlet.greenthread import sleep [as 别名]
def _ssh_execute(self, sshpool, command,
                     check_exit_code=True, attempts=1):
        try:
            with sshpool.item() as ssh:
                last_exception = None
                while attempts > 0:
                    attempts -= 1
                    try:
                        return processutils.ssh_execute(
                            ssh,
                            command,
                            check_exit_code=check_exit_code)
                    except Exception as e:
                        LOG.exception('Error has occurred')
                        last_exception = e
                        greenthread.sleep(1)

                try:
                    raise processutils.ProcessExecutionError(
                        exit_code=last_exception.exit_code,
                        stdout=last_exception.stdout,
                        stderr=last_exception.stderr,
                        cmd=last_exception.cmd)
                except AttributeError:
                    raise processutils.ProcessExecutionError(
                        exit_code=-1,
                        stdout="",
                        stderr="Error running SSH command",
                        cmd=command)

        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error("Error running SSH command: %s", command) 
开发者ID:openstack,项目名称:manila,代码行数:35,代码来源:cli_helper.py

示例2: delay

# 需要导入模块: from eventlet import greenthread [as 别名]
# 或者: from eventlet.greenthread import sleep [as 别名]
def delay(self, attempt):
        interval = int(self.backoff_factor * (2 ** (attempt - 1)))
        LOG.debug('Waiting for %(interval)s seconds',
                  {'interval': interval})
        greenthread.sleep(interval) 
开发者ID:openstack,项目名称:manila,代码行数:7,代码来源:jsonrpc.py

示例3: execute

# 需要导入模块: from eventlet import greenthread [as 别名]
# 或者: from eventlet.greenthread import sleep [as 别名]
def execute(cmd, root_helper=None, process_input=None, addl_env=None,
            check_exit_code=True, return_stderr=False, debuglog=True):
    # Note(gongysh) not use log_levels in config file because
    # some other codes that are not in a loop probably need the debug log
    try:
        obj, cmd = create_process(cmd, root_helper=root_helper,
                                  addl_env=addl_env, debuglog=debuglog)
        _stdout, _stderr = (process_input and
                            obj.communicate(process_input) or
                            obj.communicate())
        obj.stdin.close()
        m = _("\nCommand: %(cmd)s\nExit code: %(code)s\nStdout: %(stdout)r\n"
              "Stderr: %(stderr)r") % {'cmd': cmd, 'code': obj.returncode,
                                       'stdout': _stdout, 'stderr': _stderr}
        if obj.returncode:
            LOG.error(m)
            if check_exit_code:
                raise RuntimeError(m)
        elif debuglog:
            LOG.debug(m)
    finally:
        # NOTE(termie): this appears to be necessary to let the subprocess
        #               call clean something up in between calls, without
        #               it two execute calls in a row hangs the second one
        greenthread.sleep(0)

    return return_stderr and (_stdout, _stderr) or _stdout 
开发者ID:openstack,项目名称:tacker,代码行数:29,代码来源:utils.py

示例4: start

# 需要导入模块: from eventlet import greenthread [as 别名]
# 或者: from eventlet.greenthread import sleep [as 别名]
def start(self, interval, initial_delay=None):
        self._running = True
        done = event.Event()

        def _inner():
            if initial_delay:
                greenthread.sleep(initial_delay)

            try:
                while self._running:
                    start = timeutils.utcnow()
                    self.f(*self.args, **self.kw)
                    end = timeutils.utcnow()
                    if not self._running:
                        break
                    delay = interval - timeutils.delta_seconds(start, end)
                    if delay <= 0:
                        LOG.warning('task run outlasted interval '
                                    'by %s sec',
                                    -delay)
                    greenthread.sleep(delay if delay > 0 else 0)
            except LoopingCallDone as e:
                self.stop()
                done.send(e.retvalue)
            except Exception:
                done.send_exception(*sys.exc_info())
                return
            else:
                done.send(True)

        self.done = done

        greenthread.spawn_n(_inner)
        return self.done


# TODO(mikal): this class name is deprecated in Havana and should be removed
# in the I release 
开发者ID:openstack,项目名称:oslo.vmware,代码行数:40,代码来源:loopingcall.py

示例5: get_all_deployed_loadbalancers

# 需要导入模块: from eventlet import greenthread [as 别名]
# 或者: from eventlet.greenthread import sleep [as 别名]
def get_all_deployed_loadbalancers(self, purge_orphaned_folders=False):
        LOG.debug('getting all deployed loadbalancers on BIG-IPs')
        deployed_lb_dict = {}
        for bigip in self.get_all_bigips():
            folders = self.system_helper.get_folders(bigip)
            for folder in folders:
                tenant_id = folder[len(self.service_adapter.prefix):]
                if str(folder).startswith(self.service_adapter.prefix):
                    resource = resource_helper.BigIPResourceHelper(
                        resource_helper.ResourceType.virtual_address)
                    deployed_lbs = resource.get_resources(bigip, folder)
                    if deployed_lbs:
                        for lb in deployed_lbs:
                            lb_id = lb.name[len(self.service_adapter.prefix):]
                            if lb_id in deployed_lb_dict:
                                deployed_lb_dict[lb_id][
                                    'hostnames'].append(bigip.hostname)
                            else:
                                deployed_lb_dict[lb_id] = {
                                    'id': lb_id,
                                    'tenant_id': tenant_id,
                                    'hostnames': [bigip.hostname]
                                }
                    else:
                        # delay to assure we are not in the tenant creation
                        # process before a virtual address is created.
                        greenthread.sleep(10)
                        deployed_lbs = resource.get_resources(bigip, folder)
                        if deployed_lbs:
                            for lb in deployed_lbs:
                                lb_id = lb.name[
                                    len(self.service_adapter.prefix):]
                                deployed_lb_dict[lb_id] = \
                                    {'id': lb_id, 'tenant_id': tenant_id}
                        else:
                            # Orphaned folder!
                            if purge_orphaned_folders:
                                try:
                                    self.system_helper.purge_folder_contents(
                                        bigip, folder)
                                    self.system_helper.purge_folder(
                                        bigip, folder)
                                    LOG.error('orphaned folder %s on %s' %
                                              (folder, bigip.hostname))
                                except Exception as exc:
                                    LOG.error('error purging folder %s: %s' %
                                              (folder, str(exc)))
        return deployed_lb_dict 
开发者ID:F5Networks,项目名称:f5-openstack-agent,代码行数:50,代码来源:icontrol_driver.py

示例6: _get_vm_param

# 需要导入模块: from eventlet import greenthread [as 别名]
# 或者: from eventlet.greenthread import sleep [as 别名]
def _get_vm_param(self, uuid):

        try:
            # Initalize return values.
            conf_dic = self.rc_config.get_value('recover_starter')
            api_max_retry_cnt = conf_dic.get('api_max_retry_cnt')
            api_retry_interval = conf_dic.get('api_retry_interval')
            cnt = 0
            while cnt < int(api_max_retry_cnt) + 1:
                try:
                    # Call nova show API.
                    server = self.rc_util_api.do_instance_show(uuid)
                    return server
                except Exception:
                    if cnt == int(api_max_retry_cnt):
                        raise EnvironmentError("Failed to nova show API.")
                    else:
                        msg = (" Retry nova show API.")
                        LOG.info(msg)
                        greenthread.sleep(int(api_retry_interval))
                        cnt += 1

        except EnvironmentError:
            error_type, error_value, traceback_ = sys.exc_info()
            tb_list = traceback.format_tb(traceback_)
            LOG.error(error_type)
            LOG.error(error_value)
            for tb in tb_list:
                LOG.error(tb)
            raise EnvironmentError
        except KeyError:
            error_type, error_value, traceback_ = sys.exc_info()
            tb_list = traceback.format_tb(traceback_)
            LOG.error(error_type)
            LOG.error(error_value)
            for tb in tb_list:
                LOG.error(tb)
            raise KeyError
        except:
            error_type, error_value, traceback_ = sys.exc_info()
            tb_list = traceback.format_tb(traceback_)
            LOG.error(error_type)
            LOG.error(error_value)
            for tb in tb_list:
                LOG.error(tb)
            raise 
开发者ID:ntt-sic,项目名称:masakari,代码行数:48,代码来源:masakari_worker.py

示例7: _do_process_accident_vm_recovery

# 需要导入模块: from eventlet import greenthread [as 别名]
# 或者: from eventlet.greenthread import sleep [as 别名]
def _do_process_accident_vm_recovery(self, uuid, vm_state):
        # Initalize status.
        status = self.STATUS_NORMAL

        try:
            # Idealy speaking, an instance fail notification isn't sent
            # from instancemonitor if the instance is in stopped state
            # since there is no instance on the hypervisor. However,
            # in some race conditions, it could happen.
            if vm_state == 'stopped':
                self.rc_util_api.do_instance_reset(uuid, 'stopped')
                return status

            if vm_state == 'resized':
                self.rc_util_api.do_instance_reset(uuid, 'active')

            self.rc_util_api.do_instance_stop(uuid)

            # Wait to be in the Stopped.
            conf_dic = self.rc_config.get_value('recover_starter')
            api_check_interval = conf_dic.get('api_check_interval')
            api_check_max_cnt = conf_dic.get('api_check_max_cnt')
            loop_cnt = 0

            while loop_cnt < int(api_check_max_cnt):
                vm_info = self._get_vm_param(uuid)
                vm_state = getattr(vm_info, 'OS-EXT-STS:vm_state')
                if vm_state == 'stopped':
                    break
                else:
                    loop_cnt += 1
                    greenthread.sleep(int(api_check_interval))

            if loop_cnt == int(api_check_max_cnt):
                msg = "vm_state did not become stopped."
                raise EnvironmentError(msg)

            self.rc_util_api.do_instance_start(uuid)

        except EnvironmentError:
            status = self.STATUS_ERROR
            error_type, error_value, traceback_ = sys.exc_info()
            tb_list = traceback.format_tb(traceback_)
            LOG.error(error_type)
            LOG.error(error_value)
            for tb in tb_list:
                LOG.error(tb)
        except:
            status = self.STATUS_ERROR
            error_type, error_value, traceback_ = sys.exc_info()
            tb_list = traceback.format_tb(traceback_)
            LOG.error(error_type)
            LOG.error(error_value)
            for tb in tb_list:
                LOG.error(tb)

        return status 
开发者ID:ntt-sic,项目名称:masakari,代码行数:59,代码来源:masakari_worker.py

示例8: fake_execute

# 需要导入模块: from eventlet import greenthread [as 别名]
# 或者: from eventlet.greenthread import sleep [as 别名]
def fake_execute(*cmd_parts, **kwargs):
    """This function stubs out execute.

    It optionally executes a preconfigued function to return expected data.

    """
    global _fake_execute_repliers

    process_input = kwargs.get('process_input', None)
    check_exit_code = kwargs.get('check_exit_code', 0)
    delay_on_retry = kwargs.get('delay_on_retry', True)
    attempts = kwargs.get('attempts', 1)
    run_as_root = kwargs.get('run_as_root', False)
    cmd_str = ' '.join(str(part) for part in cmd_parts)

    LOG.debug("Faking execution of cmd (subprocess): %s", cmd_str)
    _fake_execute_log.append(cmd_str)

    reply_handler = fake_execute_default_reply_handler

    for fake_replier in _fake_execute_repliers:
        if re.match(fake_replier[0], cmd_str):
            reply_handler = fake_replier[1]
            LOG.debug('Faked command matched %s', fake_replier[0])
            break

    if isinstance(reply_handler, six.string_types):
        # If the reply handler is a string, return it as stdout
        reply = reply_handler, ''
    else:
        try:
            # Alternative is a function, so call it
            reply = reply_handler(cmd_parts,
                                  process_input=process_input,
                                  delay_on_retry=delay_on_retry,
                                  attempts=attempts,
                                  run_as_root=run_as_root,
                                  check_exit_code=check_exit_code)
        except exception.ProcessExecutionError as e:
            LOG.debug('Faked command raised an exception %s', e)
            raise

    stdout = reply[0]
    stderr = reply[1]
    LOG.debug("Reply to faked command is stdout='%(stdout)s' "
              "stderr='%(stderr)s'.", {"stdout": stdout, "stderr": stderr})

    # Replicate the sleep call in the real function
    greenthread.sleep(0)
    return reply 
开发者ID:openstack,项目名称:manila,代码行数:52,代码来源:fake_utils.py


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