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


Python eventlet.sleep方法代码示例

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


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

示例1: run

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def run(self):
        acceptors = []
        for sock in self.sockets:
            gsock = GreenSocket(sock)
            gsock.setblocking(1)
            hfun = partial(self.handle, gsock)
            acceptor = eventlet.spawn(_eventlet_serve, gsock, hfun,
                                      self.worker_connections)

            acceptors.append(acceptor)
            eventlet.sleep(0.0)

        while self.alive:
            self.notify()
            eventlet.sleep(1.0)

        self.notify()
        try:
            with eventlet.Timeout(self.cfg.graceful_timeout) as t:
                [a.kill(eventlet.StopServe()) for a in acceptors]
                [a.wait() for a in acceptors]
        except eventlet.Timeout as te:
            if te != t:
                raise
            [a.kill() for a in acceptors] 
开发者ID:jpush,项目名称:jbox,代码行数:27,代码来源:geventlet.py

示例2: restart

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def restart(self):
        """Restart the process."""
        if cfg.CONF.pluto.restart_check_config and not self._config_changed():
            return
        # stop() followed immediately by a start() runs the risk that the
        # current pluto daemon has not had a chance to shutdown. We check
        # the current process information to see if the daemon is still
        # running and if so, wait a short interval and retry.
        self.stop()
        wait_interval = cfg.CONF.pluto.shutdown_check_timeout
        for i in range(cfg.CONF.pluto.shutdown_check_retries):
            if not self._process_running():
                self._cleanup_control_files()
                break
            eventlet.sleep(wait_interval)
            wait_interval *= cfg.CONF.pluto.shutdown_check_back_off
        else:
            LOG.warning('Server appears to still be running, restart '
                        'of router %s may fail', self.id)
        self.start()
        return 
开发者ID:openstack,项目名称:neutron-vpnaas,代码行数:23,代码来源:ipsec.py

示例3: test_bug_330

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def test_bug_330(self):
        BUG_330 = """\
            from weakref import WeakKeyDictionary
            import eventlet

            def do():
                eventlet.sleep(.01)

            gts = WeakKeyDictionary()
            for _ in range(100):
                gts[eventlet.spawn(do)] = True
                eventlet.sleep(.005)

            eventlet.sleep(.1)
            print(len(gts))
            """
        self.try_some_code(BUG_330, "eventlet", eventlet, "0\n") 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:19,代码来源:test_concurrency.py

示例4: send_rest_api

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def send_rest_api(self, method, params=None, request_type='post'):
        attempts = 3
        msge = ''
        while attempts > 0:
            attempts -= 1
            try:
                return self.send_api(method, params, request_type)
            except exception.NetworkException as e:
                msge = six.text_type(e)
                LOG.error(msge)

                self.refresh_token(force=True)
                eventlet.sleep(1)
            except exception.ShareBackendException as e:
                msge = six.text_type(e)
                break

        msg = (_('Access RestAPI /rest/%(method)s by %(type)s failed,'
                 ' error: %(msge)s') % {'method': method,
                                        'msge': msge,
                                        'type': request_type})
        LOG.error(msg)
        raise exception.ShareBackendException(msg) 
开发者ID:openstack,项目名称:manila,代码行数:25,代码来源:as13000_nas.py

示例5: test_add_on_demand

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def test_add_on_demand(self):
        called = set()

        def cb(name):
            called.add(name)

        callables = []
        for i in range(0, 10):
            i_cb = functools.partial(cb, '%s_has_called' % i)
            callables.append((every_half_sec, (i_cb,), {}))

        leftover_callables = list(callables)
        w = periodics.PeriodicWorker([], **self.worker_kwargs)
        with self.create_destroy(w.start, allow_empty=True):
            # NOTE(harlowja): if this never happens, the test will fail
            # eventually, with a timeout error..., probably can make it fail
            # slightly faster in the future...
            while len(called) != len(callables):
                if leftover_callables:
                    cb, args, kwargs = leftover_callables.pop()
                    w.add(cb, *args, **kwargs)
                self.sleep(0.1)
            w.stop() 
开发者ID:openstack,项目名称:futurist,代码行数:25,代码来源:test_periodics.py

示例6: test_worker

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def test_worker(self):
        called = []

        def cb():
            called.append(1)

        callables = [
            (every_one_sec, (cb,), None),
            (every_half_sec, (cb,), None),
        ]
        executor = self.executor_cls(**self.executor_kwargs)
        executor_factory = lambda: executor
        w = periodics.PeriodicWorker(callables,
                                     executor_factory=executor_factory,
                                     **self.worker_kwargs)
        with self.create_destroy(w.start):
            self.sleep(2.0)
            w.stop()

        am_called = sum(called)
        self.assertGreaterEqual(am_called, 4)

        self.assertFalse(executor.alive) 
开发者ID:openstack,项目名称:futurist,代码行数:25,代码来源:test_periodics.py

示例7: test_create_with_arguments

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def test_create_with_arguments(self):
        m = mock.Mock()

        class Object(object):
            @periodics.periodic(0.5)
            def func1(self, *args, **kwargs):
                m(*args, **kwargs)

        executor_factory = lambda: self.executor_cls(**self.executor_kwargs)
        w = periodics.PeriodicWorker.create(objects=[Object()],
                                            executor_factory=executor_factory,
                                            args=('foo',),
                                            kwargs={'bar': 'baz'},
                                            **self.worker_kwargs)
        with self.create_destroy(w.start):
            self.sleep(2.0)
            w.stop()

        m.assert_called_with('foo', bar='baz') 
开发者ID:openstack,项目名称:futurist,代码行数:21,代码来源:test_periodics.py

示例8: test_start_with_auto_stop_when_empty_set

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def test_start_with_auto_stop_when_empty_set(self):

        @periodics.periodic(0.5)
        def run_only_once():
            raise periodics.NeverAgain("No need to run again !!")

        callables = [
            (run_only_once, None, None),
            (run_only_once, None, None),
        ]
        executor_factory = lambda: self.executor_cls(**self.executor_kwargs)
        w = periodics.PeriodicWorker(callables,
                                     executor_factory=executor_factory,
                                     **self.worker_kwargs)
        with self.create_destroy(w.start, auto_stop_when_empty=True):
            self.sleep(2.0)

        for watcher in w.iter_watchers():
            self.assertGreaterEqual(watcher.runs, 1)
            self.assertGreaterEqual(watcher.successes, 1)
            self.assertEqual(watcher.failures, 0)
            self.assertEqual(watcher.requested_stop, True) 
开发者ID:openstack,项目名称:futurist,代码行数:24,代码来源:test_periodics.py

示例9: test_add_with_auto_stop_when_empty_set

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def test_add_with_auto_stop_when_empty_set(self):
        m = mock.Mock()

        @periodics.periodic(0.5)
        def run_only_once():
            raise periodics.NeverAgain("No need to run again !!")

        callables = [
            (run_only_once, None, None),
        ]
        executor_factory = lambda: self.executor_cls(**self.executor_kwargs)
        w = periodics.PeriodicWorker(callables,
                                     executor_factory=executor_factory,
                                     **self.worker_kwargs)
        with self.create_destroy(w.start, auto_stop_when_empty=True):
            self.sleep(2.0)
            w.add(every_half_sec, m, None)

        m.assert_not_called() 
开发者ID:openstack,项目名称:futurist,代码行数:21,代码来源:test_periodics.py

示例10: test_retry_submission

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def test_retry_submission(self):
        called = []

        def cb():
            called.append(1)

        callables = [
            (every_one_sec, (cb,), None),
            (every_half_sec, (cb,), None),
        ]
        w = periodics.PeriodicWorker(callables,
                                     executor_factory=RejectingExecutor,
                                     cond_cls=green_threading.Condition,
                                     event_cls=green_threading.Event)
        w._RESCHEDULE_DELAY = 0
        w._RESCHEDULE_JITTER = 0
        with create_destroy_green_thread(w.start):
            eventlet.sleep(2.0)
            w.stop()

        am_called = sum(called)
        self.assertGreaterEqual(am_called, 4) 
开发者ID:openstack,项目名称:futurist,代码行数:24,代码来源:test_periodics.py

示例11: test_uri_length_limit

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def test_uri_length_limit(self):
        server = masakari.wsgi.Server("test_uri_length_limit", None,
            host="127.0.0.1", max_url_len=16384)
        server.start()

        uri = "http://127.0.0.1:%d/%s" % (server.port, 10000 * 'x')
        resp = requests.get(uri, proxies={"http": ""})
        eventlet.sleep(0)
        self.assertNotEqual(resp.status_code,
                            requests.codes.REQUEST_URI_TOO_LARGE)

        uri = "http://127.0.0.1:%d/%s" % (server.port, 20000 * 'x')
        resp = requests.get(uri, proxies={"http": ""})
        eventlet.sleep(0)
        self.assertEqual(resp.status_code,
                         requests.codes.REQUEST_URI_TOO_LARGE)
        server.stop()
        server.wait() 
开发者ID:openstack,项目名称:masakari,代码行数:20,代码来源:test_wsgi.py

示例12: run

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def run(self):
        self.connect()
        LOG.info("Starting Subscriber on ports %(endpoints)s",
                 {'endpoints': self.uri_list})
        while True:
            try:
                eventlet.sleep(0)
                [topic, data] = self.sub_socket.recv_multipart()
                self._handle_incoming_event(data)
            except Exception:
                exception_tb = traceback.format_exc()
                LOG.warning('Exception caught.\n%s', (exception_tb,))
                self.sub_socket.close()
                self.connect()
                self.db_changes_callback(None, None, 'sync',
                                         None, None) 
开发者ID:openstack,项目名称:dragonflow,代码行数:18,代码来源:zmq_pubsub_driver.py

示例13: test_uri_length_limit

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def test_uri_length_limit(self):
        eventlet.monkey_patch(os=False, thread=False)
        server = wsgi.Server(self.conf, "test_uri_length_limit", None,
                             host="127.0.0.1", max_url_len=16384, port=33337)
        server.start()
        self.assertFalse(server._server.dead)

        uri = "http://127.0.0.1:%d/%s" % (server.port, 10000 * 'x')
        resp = requests.get(uri, proxies={"http": ""})
        eventlet.sleep(0)
        self.assertNotEqual(requests.codes.REQUEST_URI_TOO_LARGE,
                            resp.status_code)

        uri = "http://127.0.0.1:%d/%s" % (server.port, 20000 * 'x')
        resp = requests.get(uri, proxies={"http": ""})
        eventlet.sleep(0)
        self.assertEqual(requests.codes.REQUEST_URI_TOO_LARGE,
                         resp.status_code)
        server.stop()
        server.wait() 
开发者ID:openstack,项目名称:oslo.service,代码行数:22,代码来源:test_wsgi.py

示例14: config_vnf

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def config_vnf(self, context, vnf_dict):
        config = vnf_dict['attributes'].get('config')
        if not config:
            return
        if isinstance(config, str):
            # TODO(dkushwaha) remove this load once db supports storing
            # json format of yaml files in a separate column instead of
            #  key value string pairs in vnf attributes table.
            config = yaml.safe_load(config)

        eventlet.sleep(self.boot_wait)      # wait for vm to be ready
        vnf_id = vnf_dict['id']
        update = {
            'vnf': {
                'id': vnf_id,
                'attributes': {'config': config},
            }
        }
        self.update_vnf(context, vnf_id, update) 
开发者ID:openstack,项目名称:tacker,代码行数:21,代码来源:plugin.py

示例15: cooperative_iter

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import sleep [as 别名]
def cooperative_iter(iter):
    """Prevent eventlet thread starvation during iteration

    Return an iterator which schedules after each
    iteration. This can prevent eventlet thread starvation.

    :param iter: an iterator to wrap
    """
    try:
        for chunk in iter:
            sleep(0)
            yield chunk
    except Exception as err:
        with excutils.save_and_reraise_exception():
            msg = _("Error: cooperative_iter exception %s") % err
            LOG.error(msg) 
开发者ID:openstack,项目名称:tacker,代码行数:18,代码来源:utils.py


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