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


Python gevent.spawn_later方法代码示例

本文整理汇总了Python中gevent.spawn_later方法的典型用法代码示例。如果您正苦于以下问题:Python gevent.spawn_later方法的具体用法?Python gevent.spawn_later怎么用?Python gevent.spawn_later使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gevent的用法示例。


在下文中一共展示了gevent.spawn_later方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_connection_failure

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def handle_connection_failure(self, conn):
        del self._connections[conn]
        conn.close_stream()

        if not self.is_running:
            return

        self.redistribute_ready_state()

        if str(conn) not in self.nsqd_tcp_addresses:
            return

        seconds = self._connection_backoffs[conn].failure().get_interval()
        self.logger.debug('[%s] retrying in %ss', conn, seconds)

        gevent.spawn_later(
            seconds, self.connect_to_nsqd, conn.address, conn.port) 
开发者ID:wtolson,项目名称:gnsq,代码行数:19,代码来源:consumer.py

示例2: _clean_local_backup

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def _clean_local_backup(local_backup_file, g):
    def _safe_remove(path):
        LOG.info('Removing backup {}'.format(local_backup_file))
        try:
            os.remove(path)
        except:
            pass

    if g.value != 0:
        _safe_remove(local_backup_file)
        return

    LOG.info('Removing backup {} in 300s'.format(local_backup_file))
    gevent.spawn_later(300, _safe_remove, local_backup_file)


# XXX this should be moved to a different endpoint 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:19,代码来源:statusapi.py

示例3: __call__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def __call__(self, *args, **kwargs):
        now = utc_millisec()
        remaining = self.wait - (now - self._previous)

        if self._cancelled:
            return

        if remaining <= 0 or remaining > self.wait:
            if self._timeout is not None:
                self._timeout.join(timeout=5)
                self._timeout = None
            self._previous = now
            self.f(*args, **kwargs)

        elif self._timeout is None:
            self._args = args
            self._kwargs = kwargs
            self._timeout = gevent.spawn_later(remaining/1000.0, self.later)

        else:
            self._args = args
            self._kwargs = kwargs 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:24,代码来源:utils.py

示例4: start

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def start(self):
        super(BasePollerFT, self).start()

        if self._actor_glet is not None:
            return

        self._actor_glet = gevent.spawn(
            self._actor_loop
        )
        self._poll_glet = gevent.spawn_later(
            random.randint(0, 2),
            self._poll_loop
        )

        self._age_out_glet = gevent.spawn(
            self._age_out_loop
        ) 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:19,代码来源:basepoller.py

示例5: set

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def set(self, interval, callback, repeat=False, force=True):
        """
        添加timer
        """
        if self.timer:
            if force:
                # 如果已经存在,那么先要把现在的清空
                self.clear()
            else:
                # 已经存在的话,就返回了
                return

        def callback_wrapper():
            # 必须要确定,这次调用就是这个timer引起的
            if self.timer == timer:
                # 必须加这句,否则如果在callback中有clear操作,会出现GreenletExit
                self.timer = None
                # 不可以加 timer = None,否则会导致判断self.timer == timer 报错找不到timer
                result = safe_call(callback)
                if repeat and not self.timer:
                    # 之所以还要判断timer,是因为callback中可能设置了新的回调
                    self.set(interval, callback, repeat, True)
                return result

        self.timer = timer = gevent.spawn_later(interval, callback_wrapper) 
开发者ID:dantezhu,项目名称:haven,代码行数:27,代码来源:gevent_impl.py

示例6: handle_incoming_call

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def handle_incoming_call(self, caller_username, backend_server_url):
        if self.videocall_user is None:
            raise JanusCloudError('Register a username first', JANUS_VIDEOCALL_ERROR_REGISTER_FIRST)
        if self.videocall_user.incall:
            raise JanusCloudError('User {} busy'.format(self.videocall_user.username), JANUS_VIDEOCALL_ERROR_ALREADY_IN_CALL)
        self.videocall_user.incall = True
        self.videocall_user.peer_name = caller_username
        self.videocall_user.utime = time.time()
        try:
            self._connect_backend(backend_server_url)
            self._plugin.user_dao.update(self.videocall_user)
        except Exception:
            self._disconnect_backend()
            self.videocall_user.peer_name = ''
            self.videocall_user.incall = False
            raise

        # if incoming_call event cannot be received in INCOMMING_CALL_TIMEOUT(10) seconds,
        # auto disconnect the backend server
        if self._auto_disconnect_greenlet is None:
            self._auto_disconnect_greenlet = gevent.spawn_later(INCOMMING_CALL_TIMEOUT, self._auto_disconnect_routine) 
开发者ID:OpenSight,项目名称:janus-cloud,代码行数:23,代码来源:videocall.py

示例7: _keepalive_routine

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def _keepalive_routine(self):
        gevent.sleep(self._keepalive_interval)
        keepalive_msg = create_janus_msg('keepalive')
        while self.state == BACKEND_SESSION_STATE_ACTIVE:
            try:
                # if there is no handle existed and auto destroy is enabled, just schedule the destroy route
                if not self._handles:
                    if self._auto_destroy and self._auto_destroy_greenlet is None:
                        self._auto_destroy_greenlet = gevent.spawn_later(self._auto_destroy, self._auto_destroy_routine)

                self.send_request(keepalive_msg, ignore_ack=False)

            except Exception as e:
                log.exception('Keepalive failed for backend session {}'.format(self.url))
                self.destroy()
            else:
                gevent.sleep(self._keepalive_interval) 
开发者ID:OpenSight,项目名称:janus-cloud,代码行数:19,代码来源:backend_session.py

示例8: refresh_cache

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def refresh_cache():
    global ROLES
    refresh_rate = settings.BACKGROUND_CACHE_IAM_ROLE_REFRESH_RATE
    if settings.BACKGROUND_CACHE_IAM_ROLE_REFRESH_RATE < 60:
        refresh_rate = 60
    try:
        logger.info('Refreshing IAM roles cache.')
        ROLES = _get_iam_roles()
    except Exception:
        logger.exception(
            'Failed to update IAM roles cache.',
            exc_info=True
        )
    finally:
        # +/- 20ish seconds for respawn, to ensure all processes do not
        # refresh at the same time
        random_refresh_rate = random.randrange(
            refresh_rate - 20,
            refresh_rate + 20
        )
        return gevent.spawn_later(
            random_refresh_rate,
            refresh_cache
        ) 
开发者ID:lyft,项目名称:confidant,代码行数:26,代码来源:iamrolemanager.py

示例9: testPoolJoin

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def testPoolJoin(self):
        with create_actor_pool(address=True, n_process=2, distributor=AdminDistributor(2),
                               backend='gevent') as pool:
            start = time.time()
            pool.join(0.2)
            self.assertGreaterEqual(time.time() - start, 0.2)

            start = time.time()
            gevent.spawn_later(0.2, lambda: pool.stop())
            pool.join()
            self.assertGreaterEqual(time.time() - start, 0.2) 
开发者ID:mars-project,项目名称:mars,代码行数:13,代码来源:test_gevent_pool.py

示例10: handle_connection_failure

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def handle_connection_failure(self, conn):
        conn.close_stream()
        self._clear_responses(conn, NSQException('connection closed'))

        if not self.is_running:
            return

        seconds = self._connection_backoffs[conn].failure().get_interval()
        self.logger.debug('[%s] retrying in %ss', conn, seconds)

        gevent.spawn_later(
            seconds, self.connect_to_nsqd, conn.address, conn.port) 
开发者ID:wtolson,项目名称:gnsq,代码行数:14,代码来源:producer.py

示例11: _start_backoff

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def _start_backoff(self, conn):
        self._connections[conn] = BACKOFF

        interval = self._message_backoffs[conn].get_interval()
        gevent.spawn_later(interval, self._start_throttled, conn)

        self.logger.info('[%s] backing off for %s seconds', conn, interval)
        self.redistribute_ready_state() 
开发者ID:wtolson,项目名称:gnsq,代码行数:10,代码来源:consumer.py

示例12: set_timer

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def set_timer(self, t, f, *args, **kw):
        timer = None

        def wrapper():
            self._timers.discard(timer)
            f(*args, **kw)

        timer = spawn_later(t, wrapper)
        self._timers.add(timer)
        return timer 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:12,代码来源:__init__.py

示例13: start

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def start(self):
        super(PanOSLogsAPIFT, self).start()

        if self.glet is not None:
            return

        self.glet = gevent.spawn_later(random.randint(0, 2), self._run)

        for idx in range(len(self.fields)):
            self.age_out_glets.append(
                gevent.spawn(self._age_out_loop, idx)
            ) 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:14,代码来源:panos.py

示例14: start

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def start(self):
        super(DagPusher, self).start()

        if self.device_list_glet is not None:
            return

        self.device_list_glet = gevent.spawn_later(
            2,
            self._device_list_monitor
        )

        if self.age_out_interval is not None:
            self.ageout_glet = gevent.spawn(self._age_out_run) 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:15,代码来源:dag_ng.py

示例15: start

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import spawn_later [as 别名]
def start(self):
        super(TestMiner, self).start()

        self._glet = gevent.spawn_later(
            2,
            self._run
        ) 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:9,代码来源:test.py


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