當前位置: 首頁>>代碼示例>>Python>>正文


Python gevent.sleep方法代碼示例

本文整理匯總了Python中gevent.sleep方法的典型用法代碼示例。如果您正苦於以下問題:Python gevent.sleep方法的具體用法?Python gevent.sleep怎麽用?Python gevent.sleep使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gevent的用法示例。


在下文中一共展示了gevent.sleep方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_exitcode_previous_to_join

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def test_exitcode_previous_to_join(self):
        p = start_process(lambda: gevent.sleep(SHORTTIME))
        # Assume that the child process is still alive when the next
        # line is executed by the interpreter (there is no guarantee
        # for that, but it's rather likely).
        assert p.exitcode is None

        # Expect the child watcher mechanism to pick up
        # and process the child process termination event
        # (within at most two seconds). The `gevent.sleep()`
        # invocations allow for libev event loop iterations,
        # two of which are required after the OS delivers the
        # SIGCHLD signal to the parent process: one iteration
        # invokes the child reap loop, and the next invokes
        # the libev callback associated with the termination
        # event.
        deadline = time.time() + 2
        while time.time() < deadline:
            if p.exitcode is not None:
                assert p.exitcode == 0
                p.join()
                return
            gevent.sleep(ALMOSTZERO)
        raise Exception('Child termination not detected') 
開發者ID:jgehrcke,項目名稱:gipc,代碼行數:26,代碼來源:test_gipc.py

示例2: test_lock_out_of_context_single

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def test_lock_out_of_context_single(self):
        r, w = pipe()
        g = gevent.spawn(lambda r: r.get(), r)
        gevent.sleep(SHORTTIME)
        with raises(GIPCLocked):
            with r:
                pass
                # The context manager can't close `r`, as it is locked in `g`.
        g.kill(block=False)
        # Ensure killing via 'context switch', i.e. yield control to other
        # coroutines (otherwise the subsequent close attempt will fail with
        # `GIPCLocked` error).
        gevent.sleep(-1)
        # Close writer first. otherwise, `os.close(r._fd)` would block on Win.
        w.close()
        r.close() 
開發者ID:jgehrcke,項目名稱:gipc,代碼行數:18,代碼來源:test_gipc.py

示例3: test_lock_out_of_context_pair

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def test_lock_out_of_context_pair(self):
        with raises(GIPCLocked):
            with pipe(True) as (h1, h2):
                # Write more to pipe than pipe buffer can hold
                # (makes `put` block when there is no reader).
                # Buffer is quite large on Windows.
                gw = gevent.spawn(lambda h: h.put(LONGERTHANBUFFER), h1)
                gevent.sleep(SHORTTIME)
                # Context manager tries to close h2 reader, h2 writer, and
                # h1 writer first. Fails upon latter, must still close
                # h1 reader after that.
        assert not h1._writer._closed
        assert h1._reader._closed
        assert h2._writer._closed
        assert h2._reader._closed
        # Kill greenlet (free lock on h1 writer), close h1 writer.
        gw.kill(block=False)
        gevent.sleep(-1)
        h1.close()
        assert h1._writer._closed 
開發者ID:jgehrcke,項目名稱:gipc,代碼行數:22,代碼來源:test_gipc.py

示例4: test_lock_out_of_context_pair_3

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def test_lock_out_of_context_pair_3(self):
        with raises(GIPCLocked):
            with pipe(True) as (h1, h2):
                gr1 = gevent.spawn(lambda h: h.get(), h1)
                gr2 = gevent.spawn(lambda h: h.get(), h2)
                gevent.sleep(SHORTTIME)
                # Context succeeds closing h2 writer, fails upon closing h2
                # reader. Proceeds closing h1 writer, succeeds, closes h1
                # reader and fails.
        assert not h2._reader._closed
        assert not h1._reader._closed
        assert h2._writer._closed
        assert h1._writer._closed
        gr1.kill(block=False)
        gr2.kill(block=False)
        gevent.sleep(-1)
        h2.close()
        h1.close() 
開發者ID:jgehrcke,項目名稱:gipc,代碼行數:20,代碼來源:test_gipc.py

示例5: test_lock_out_of_context_pair_4

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def test_lock_out_of_context_pair_4(self):
        with raises(GIPCLocked):
            with pipe(True) as (h1, h2):
                # Write more to pipe than pipe buffer can hold
                # (makes `put` block when there is no reader).
                # Buffer is quite large on Windows.
                gw1 = gevent.spawn(lambda h: h.put(LONGERTHANBUFFER), h1)
                gw2 = gevent.spawn(lambda h: h.put(LONGERTHANBUFFER), h2)
                gevent.sleep(SHORTTIME)
                # Context fails closing h2 writer, succeeds upon closing h2
                # reader. Proceeds closing h1 writer, fails, closes h1
                # reader and succeeds.
        assert h2._reader._closed
        assert h1._reader._closed
        assert not h2._writer._closed
        assert not h1._writer._closed
        gw1.kill(block=False)
        gw2.kill(block=False)
        gevent.sleep(-1)
        h2.close()
        h1.close() 
開發者ID:jgehrcke,項目名稱:gipc,代碼行數:23,代碼來源:test_gipc.py

示例6: watch

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def watch(self):
        import gevent

        cur_endpoints = self.get()
        yield cur_endpoints

        while True:
            if len(cur_endpoints) == self._expected_instances:
                linger = 10
            else:
                linger = 1

            gevent.sleep(linger)
            mtime = self._get_mtime()
            if mtime == self._endpoint_last_modified:
                continue

            self._endpoint_last_modified = mtime
            cur_endpoints = self.get()
            yield cur_endpoints 
開發者ID:mars-project,項目名稱:mars,代碼行數:22,代碼來源:core.py

示例7: daemon_thread

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def daemon_thread(mars_app, app_client, key_prefix, endpoint_file):
    last_eps = set()
    while True:
        try:
            cid_to_endpoint = dict()
            for val in app_client.kv.get_prefix(key_prefix).values():
                ep, cid = to_str(val).split('@', 1)
                cid_to_endpoint[cid] = ep

            containers = app_client.get_containers([MarsSchedulerConfig.service_name], states=['RUNNING'])
            eps = set()
            for container in containers:
                if container.yarn_container_id not in cid_to_endpoint:
                    continue
                eps.add(cid_to_endpoint[container.yarn_container_id])

            if eps != last_eps:
                logger.info('New endpoints retrieved: %r', eps)
                with open(endpoint_file, 'w') as file_obj:
                    file_obj.write('\n'.join(eps))
                last_eps = eps
            time.sleep(1)
        except SkeinError:
            mars_app._running = False
            break 
開發者ID:mars-project,項目名稱:mars,代碼行數:27,代碼來源:core.py

示例8: wait_all_schedulers_ready

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def wait_all_schedulers_ready(self):
        """
        Wait till all containers are ready, both in yarn and in ClusterInfoActor
        """
        from ...scheduler.utils import SchedulerClusterInfoActor

        # check if all schedulers are ready using Kubernetes API
        sleep_fun = (getattr(self, 'pool', None) or time).sleep
        while not self.scheduler_discoverer.is_all_ready():
            sleep_fun(1)
        yarn_schedulers = self.scheduler_discoverer.get()

        logger.debug('Schedulers all ready in yarn, waiting ClusterInfoActor to be ready')
        # check if all schedulers are registered in ClusterInfoActor
        actor_client = new_client()
        while True:
            cluster_info = actor_client.actor_ref(
                SchedulerClusterInfoActor.default_uid(), address=random.choice(yarn_schedulers))
            cluster_info_schedulers = cluster_info.get_schedulers()
            if set(cluster_info_schedulers) == set(yarn_schedulers):
                break
            sleep_fun(1)  # pragma: no cover 
開發者ID:mars-project,項目名稱:mars,代碼行數:24,代碼來源:core.py

示例9: read

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def read(self, size):
        while len(self.buffer) < size:
            self.ensure_connection()

            try:
                packet = self.socket.recv(self.buffer_size)
            except socket.error as error:
                if error.errno in (EDEADLK, EAGAIN, EWOULDBLOCK):
                    gevent.sleep()
                    continue
                six.raise_from(NSQSocketError(*error.args), error)

            if not packet:
                self.close()

            self.buffer += packet

        data = self.buffer[:size]
        self.buffer = self.buffer[size:]

        return data 
開發者ID:wtolson,項目名稱:gnsq,代碼行數:23,代碼來源:stream.py

示例10: _job_timeout_glet

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def _job_timeout_glet(self, job_group, jobid, timeout):
        gevent.sleep(timeout)

        prefix = REDIS_JOBS_GROUP_PREFIX.format(job_group)

        jobdata = self.SR.hget(prefix, jobid)
        if jobdata is None:
            return

        jobdata = json.loads(jobdata)
        status = jobdata.get('status', None)
        if status != 'RUNNING':
            LOG.info('Timeout for job {}-{} triggered but status not running'.format(prefix, jobid))
            return

        pid = jobdata.get('pid', None)
        if pid is None:
            LOG.error('Timeout for job {}-{} triggered but no pid available'.format(prefix, jobid))
            return

        LOG.error('Timeout for job {}-{} triggered, sending TERM signal'.format(prefix, jobid))
        os.kill(pid, signal.SIGTERM) 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:24,代碼來源:jobs.py

示例11: publish

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def publish(self, method, params=None):
        if self.socket is None:
            raise RuntimeError('Not connected')

        if params is None:
            params = {}

        id_ = str(uuid.uuid1())

        body = {
            'method': method,
            'id': id_,
            'params': params
        }

        try:
            self.socket.send_json(
                obj=body,
                flags=zmq.NOBLOCK
            )
        except zmq.ZMQError:
            LOG.error('Topic {} queue full - dropping message'.format(self.topic))

        gevent.sleep(0) 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:26,代碼來源:zmqredis.py

示例12: _compact_loop

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def _compact_loop(self):
        gevent.sleep(self.compact_delay)

        while True:
            try:
                gevent.idle()

                counter = 0
                for idx in self.indexes.keys():
                    for i in self.query(index=idx, include_value=False):
                        if counter % 512 == 0:
                            gevent.sleep(0.001)  # yield to other greenlets
                        counter += 1

            except gevent.GreenletExit:
                break
            except:
                LOG.exception('Exception in _compact_loop')

            try:
                gevent.sleep(self.compact_interval)

            except gevent.GreenletExit:
                break 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:26,代碼來源:table.py

示例13: _publisher

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def _publisher(self):
        while True:
            self._xmpp_client_ready.wait()

            try:
                while True:
                    cmd, indicator, value = self.q.peek()
                    if value is None:
                        value = {}
                    value['origins'] = [self.jid]
                    self._xmpp_publish(cmd, {
                        'indicator': indicator,
                        'value': value
                    })
                    _ = self.q.get()

            except gevent.GreenletExit:
                break

            except Exception as e:
                LOG.exception('%s - Exception in publishing message', self.name)
                gevent.sleep(30)
                self.statistics['xmpp.publish_error'] += 1 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:25,代碼來源:xmpp.py

示例14: _age_out_loop

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def _age_out_loop(self):
        while True:
            with self.state_lock:
                if self.state != ft_states.STARTED:
                    break

            self._actor_queue.put(
                (utc_millisec(), 'age_out')
            )

            if self.age_out['interval'] is None:
                break

            try:
                gevent.sleep(self.age_out['interval'])
            except gevent.GreenletExit:
                break 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:19,代碼來源:basepoller.py

示例15: _run

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import sleep [as 別名]
def _run(self):
    print("My Greenlet executing")
    gevent.sleep(self.seconds) 
開發者ID:PacktPublishing,項目名稱:Learning-Concurrency-in-Python,代碼行數:5,代碼來源:greenlet.py


注:本文中的gevent.sleep方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。