本文整理汇总了Python中gevent.pool.spawn方法的典型用法代码示例。如果您正苦于以下问题:Python pool.spawn方法的具体用法?Python pool.spawn怎么用?Python pool.spawn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gevent.pool
的用法示例。
在下文中一共展示了pool.spawn方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_delta_data
# 需要导入模块: from gevent import pool [as 别名]
# 或者: from gevent.pool import spawn [as 别名]
def download_delta_data(stocks, pool_size=40):
"""
Download delta data for all stocks collections of all libraries.
:param stocks: stock code list.
:param pool_size: the pool size of gevent.pool.Pool.
:return: None
"""
pool = gevent.pool.Pool(pool_size)
for i in range(len(stocks) // pool_size + 1):
start = i * pool_size
end = (i + 1) * pool_size
lst = stocks[start:end]
logger.debug(f'download delta data for stock list: {lst}')
for stock in lst:
pool.spawn(bdt.TsHisData.download_one_delta_data, stock)
pool.join(timeout=30)
示例2: async_routine
# 需要导入模块: from gevent import pool [as 别名]
# 或者: from gevent.pool import spawn [as 别名]
def async_routine(f):
@wraps(f)
def to_list(*args, **kwargs):
output = f(*args, **kwargs)
if output is not None:
return list(output)
def async_wrapped_routine(*args, **kwargs):
run_async = kwargs.pop('async', True)
if enabled and run_async:
logger.debug('Spawning greenlet to run {}({}) asynchronously'.format(f.func_name, args))
return spawn(to_list, *args, **kwargs)
else:
logger.debug('Asynchronous support disabled. Running {}({}) in a thread'.format(f.func_name, args))
to_list(*args, **kwargs)
return async_wrapped_routine
示例3: send_alarm
# 需要导入模块: from gevent import pool [as 别名]
# 或者: from gevent.pool import spawn [as 别名]
def send_alarm(ev):
backends = get_relevant_backends(ev)
for p in backends:
try:
ev1 = copy.deepcopy(ev)
rst = call_hooks('send_alarm', (ev1, p))
if not rst:
continue
ev1, _ = rst
log.debug('Sending alarm via backend %s', p.__class__.__name__)
gevent.spawn(p.send, ev1)
except Exception:
log.exception('Error sending alarm')
示例4: process_events
# 需要导入模块: from gevent import pool [as 别名]
# 或者: from gevent.pool import spawn [as 别名]
def process_events():
r = redis.from_url(State.config['redis'])
queues = [
'satori-events:%s' % i for i in range(15)
]
while True:
o, raw = r.blpop(queues)
pool.spawn(process_single_event, json.loads(raw))
示例5: start
# 需要导入模块: from gevent import pool [as 别名]
# 或者: from gevent.pool import spawn [as 别名]
def start(self):
pool = gevent.pool.Pool(size=self.concurrency)
try:
for i in xrange(1, self.num_connectors + 1):
pool.spawn(self.connector)
time.sleep(self.spawn_interval)
pool.join()
except KeyboardInterrupt:
pass
示例6: schedule_green_jobs
# 需要导入模块: from gevent import pool [as 别名]
# 或者: from gevent.pool import spawn [as 别名]
def schedule_green_jobs(
fns, concurrency=DEFAULT_THREADS,
progress=None, total=None
):
import gevent.pool
if total is None:
try:
total = len(fns)
except TypeError: # generators don't have len
pass
pbar = tqdm(total=total, desc=progress, disable=(not progress))
results = []
def updatefn(fn):
def realupdatefn():
res = fn()
pbar.update(1)
results.append(res)
return realupdatefn
pool = gevent.pool.Pool(concurrency)
for fn in fns:
pool.spawn( updatefn(fn) )
pool.join()
pool.kill()
pbar.close()
return results
示例7: run_items
# 需要导入模块: from gevent import pool [as 别名]
# 或者: from gevent.pool import spawn [as 别名]
def run_items(self, items, session, workers=None):
import gevent
import gevent.monkey
import gevent.pool
gevent.monkey.patch_all()
pool = gevent.pool.Pool(size=workers)
for index, item in enumerate(items):
pool.spawn(self._run_next_item, session, item, index)
pool.join()