Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# exiting because of timeout (the spawned greenlet still runs)
for _ in xrange(2):
x = gevent.spawn_later(10, lambda: 5)
with expected_time(SMALL):
result = gevent.wait(timeout=SMALL)
assert result is False, repr(result)
assert not x.dead, (x, x._start_event)
x.kill()
with no_time():
result = gevent.wait()
assert result is True
# exiting because of event (the spawned greenlet still runs)
for _ in xrange(2):
x = gevent.spawn_later(10, lambda: 5)
event = Event()
event_set = gevent.spawn_later(SMALL, event.set)
with expected_time(SMALL):
result = gevent.wait([event])
assert result == [event], repr(result)
assert not x.dead, x
assert event_set.dead
assert event.is_set()
x.kill()
with no_time():
result = gevent.wait()
assert result is True
# checking "ref=False" argument
for _ in xrange(2):
gevent.get_hub().loop.timer(10, ref=False).start(lambda: None)
# it will behave as expected (no data is read)
rand_reader = random.Random(seeds['reader'])
for x in xrange(config.readwrite.readers):
this_rand = random.Random(rand_reader.randrange(2**32))
group.spawn(
reader,
bucket=bucket,
worker_id=x,
file_names=file_names,
queue=q,
rand=this_rand,
)
def stop():
group.kill(block=True)
q.put(StopIteration)
gevent.spawn_later(config.readwrite.duration, stop)
# wait for all the tests to finish
group.join()
print 'post-join, queue size {size}'.format(size=q.qsize())
if q.qsize() > 0:
for temp_dict in q:
if 'error' in temp_dict:
raise Exception('exception:\n\t{msg}\n\t{trace}'.format(
msg=temp_dict['error']['msg'],
trace=temp_dict['error']['traceback'])
)
else:
yaml.safe_dump(temp_dict, stream=real_stdout)
finally:
def entrypoint():
with self.tracer.trace('greenlet.main') as span:
span.resource = 'base'
jobs = [gevent.spawn_later(0.01, green_1), gevent.spawn_later(0.01, green_2)]
gevent.joinall(jobs)
def test_inc(self):
self.pool = ThreadPool(0)
done = []
gevent.spawn(self.pool.spawn, done.append, 1)
gevent.spawn_later(0.0001, self.pool.spawn, done.append, 2)
gevent.sleep(0.01)
self.assertEqual(done, [])
self.pool.maxsize = 1
gevent.sleep(0.01)
self.assertEqual(done, [1, 2])
def test_trace_concurrent_spawn_later_calls(self):
# create multiple futures so that we expect multiple
# traces instead of a single one, even if greenlets
# are delayed
def greenlet():
with self.tracer.trace('greenlet'):
gevent.sleep(0.01)
jobs = [gevent.spawn_later(0.01, greenlet) for x in range(100)]
gevent.joinall(jobs)
traces = self.tracer.writer.pop_traces()
assert 100 == len(traces)
assert 1 == len(traces[0])
assert 'greenlet' == traces[0][0].name
def __init__(self, username, conn_id):
self.username = username # hold user id/name of connection
self.last_active = None
self.socket = None
self.queue = None
self.id = conn_id
self.mark_activity()
gevent.spawn_later(5, self.heartbeat_forever)
def receive(self, msg):
if msg.opcode in {'matchmaking', 'challenging', 'challenged'}:
self._join(msg)
elif msg.opcode == 'update-challenges':
self._update(msg.data)
elif msg.opcode == 'search-cancelled-by-server':
# Hack: disregard the wait lock, send out a search again in a few seconds.
def fn():
if not self._s.status or self._s.status.opcode != 'matchmaking':
self.die('Unknown status, search cancelled but not matchmaking: [%r]', self._s.status)
else:
self._update_status(self._s.status)
gevent.spawn_later(3.0, fn)
elif msg.opcode == 'battle-started':
if self._s.status is None:
self.die('received a [%r] cmd but no waiting battle-req to complete', msg)
else:
self._release_wait_lock()
self._s.status = None
elif msg.opcode == 'battle-ended':
self._release_count_sem()
else:
self.die('got unexpected message: %s', msg)
def planOutage(self):
'''Plans when the next outage will occur.'''
start_outage=uniform(self.min_outage_start, self.max_outage_start)
spawn_later(start_outage,self.executeOutage)
self.logging.info('Next outage is planned at %s'%(strftime("%a, %d %b %Y %H:%M:%S +0000", localtime(time()+start_outage))))
def main():
objlist = []
objlist.append(gevent.spawn_later(1, worker, "1", ct.SYNCSTOCK2REDIS, pd.DataFrame(), ct.STOCK_INFO, ['code']))
objlist.append(gevent.spawn_later(1, worker, "2", ct.SYNCCAL2REDIS, pd.DataFrame(), ct.CALENDAR_INFO, ['calendarDate']))
objlist.append(gevent.spawn_later(1, worker, "3", ct.SYNC_COMBINATION_2_REDIS, pd.DataFrame(), ct.COMBINATION_INFO, ['code']))
objlist.append(gevent.spawn_later(1, worker, "4", ct.SYNC_HALTED_2_REDIS, pd.DataFrame(), ct.HALTED_INFO, ['code','date']))
objlist.append(gevent.spawn_later(1, worker, "5", ct.SYNC_DELISTED_2_REDIS, pd.DataFrame(), ct.DELISTED_INFO, ['code']))
objlist.append(gevent.spawn_later(1, worker, "6", ct.SYNC_ANIMATION_2_REDIS, pd.DataFrame(), ct.ANIMATION_INFO, ['date','time','name']))
gevent.joinall(objlist)
def timerCaller(secs, func, *args, **kwargs):
gevent.spawn_later(secs, timerCaller, secs, func, *args, **kwargs)
func(*args, **kwargs)