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


Python pool.spawn方法代码示例

本文整理汇总了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) 
开发者ID:pandalibin,项目名称:backtrader-cn,代码行数:19,代码来源:data_main.py

示例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 
开发者ID:mitre,项目名称:cascade-server,代码行数:18,代码来源:async.py

示例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') 
开发者ID:leancloud,项目名称:satori,代码行数:17,代码来源:main.py

示例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)) 
开发者ID:leancloud,项目名称:satori,代码行数:11,代码来源:main.py

示例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 
开发者ID:cloudregistry,项目名称:eppy,代码行数:12,代码来源:session.py

示例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 
开发者ID:seung-lab,项目名称:cloud-volume,代码行数:33,代码来源:scheduler.py

示例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() 
开发者ID:reverbc,项目名称:pytest-concurrent,代码行数:11,代码来源:asyncnet.py


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