本文整理汇总了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')
示例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()
示例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
示例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()
示例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()
示例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
示例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
示例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
示例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
示例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)
示例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)
示例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
示例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
示例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
示例15: _run
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import sleep [as 别名]
def _run(self):
print("My Greenlet executing")
gevent.sleep(self.seconds)