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