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


Python eventlet.spawn方法代码示例

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


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

示例1: request_vif

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def request_vif(self, pod, project_id, subnets, security_groups):
        try:
            host_addr = self._get_host_addr(pod)
        except KeyError:
            return None

        pool_key = self._get_pool_key(host_addr, project_id, None, subnets)

        try:
            return self._get_port_from_pool(pool_key, pod, subnets,
                                            tuple(sorted(security_groups)))
        except exceptions.ResourceNotReady:
            LOG.debug("Ports pool does not have available ports: %s",
                      pool_key)
            eventlet.spawn(self._populate_pool, pool_key, pod, subnets,
                           tuple(sorted(security_groups)))
            raise 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:19,代码来源:vif_pool.py

示例2: _eventlet_serve

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def _eventlet_serve(sock, handle, concurrency):
    """
    Serve requests forever.

    This code is nearly identical to ``eventlet.convenience.serve`` except
    that it attempts to join the pool at the end, which allows for gunicorn
    graceful shutdowns.
    """
    pool = eventlet.greenpool.GreenPool(concurrency)
    server_gt = eventlet.greenthread.getcurrent()

    while True:
        try:
            conn, addr = sock.accept()
            gt = pool.spawn(handle, conn, addr)
            gt.link(_eventlet_stop, server_gt, conn)
            conn, addr, gt = None, None, None
        except eventlet.StopServe:
            sock.close()
            pool.waitall()
            return 
开发者ID:jpush,项目名称:jbox,代码行数:23,代码来源:geventlet.py

示例3: run

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def run(self):
        acceptors = []
        for sock in self.sockets:
            gsock = GreenSocket(sock)
            gsock.setblocking(1)
            hfun = partial(self.handle, gsock)
            acceptor = eventlet.spawn(_eventlet_serve, gsock, hfun,
                                      self.worker_connections)

            acceptors.append(acceptor)
            eventlet.sleep(0.0)

        while self.alive:
            self.notify()
            eventlet.sleep(1.0)

        self.notify()
        try:
            with eventlet.Timeout(self.cfg.graceful_timeout) as t:
                [a.kill(eventlet.StopServe()) for a in acceptors]
                [a.wait() for a in acceptors]
        except eventlet.Timeout as te:
            if te != t:
                raise
            [a.kill() for a in acceptors] 
开发者ID:jpush,项目名称:jbox,代码行数:27,代码来源:geventlet.py

示例4: test_semaphore

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def test_semaphore(self, inspect):
        slot = mock.Mock()
        slot.side_effect = lambda **k: time.sleep(.3)

        signal = Signal('tost')
        signal.connect(slot)

        x = Task.get_or_create(signal, dict(some_kwarg='foo'),
                               logger=logging.getLogger('TaskX'))
        y = Task.get_or_create(signal, dict(some_kwarg='foo'),
                               logger=logging.getLogger('TaskY'))

        eventlet.spawn(x)
        time.sleep(.1)
        eventlet.spawn(y)
        time.sleep(.1)

        assert slot.call_count == 1
        time.sleep(.4)
        assert slot.call_count == 2 
开发者ID:plexinc,项目名称:plex-for-kodi,代码行数:22,代码来源:test.py

示例5: start

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def start(self, use_eventlet=False, eventlet_monkey_patch=False, catch_signals=True):
        # First do a blocking long poll to populate the local cache, otherwise we may get racing problems
        if len(self._cache) == 0:
            self._long_poll()
        if use_eventlet:
            import eventlet
            if eventlet_monkey_patch:
                eventlet.monkey_patch()
            eventlet.spawn(self._listener)
        else:
            if catch_signals:
                import signal
                signal.signal(signal.SIGINT, self._signal_handler)
                signal.signal(signal.SIGTERM, self._signal_handler)
                signal.signal(signal.SIGABRT, self._signal_handler)
            t = threading.Thread(target=self._listener)
            t.start() 
开发者ID:filamoon,项目名称:pyapollo,代码行数:19,代码来源:apollo_client.py

示例6: test_bug_330

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def test_bug_330(self):
        BUG_330 = """\
            from weakref import WeakKeyDictionary
            import eventlet

            def do():
                eventlet.sleep(.01)

            gts = WeakKeyDictionary()
            for _ in range(100):
                gts[eventlet.spawn(do)] = True
                eventlet.sleep(.005)

            eventlet.sleep(.1)
            print(len(gts))
            """
        self.try_some_code(BUG_330, "eventlet", eventlet, "0\n") 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:19,代码来源:test_concurrency.py

示例7: schedulal_task_with_no_block

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def schedulal_task_with_no_block(self):
        if ConsumersManager.schedual_task_always_use_thread:
            t = Thread(target=self.consumer.keep_circulating(1)(self.consumer._shedual_task))
            ConsumersManager.schedulal_thread_to_be_join.append(t)
            t.start()
        else:
            if self._concurrent_mode == 1:
                t = Thread(target=self.consumer.keep_circulating(1)(self.consumer._shedual_task))
                ConsumersManager.schedulal_thread_to_be_join.append(t)
                t.start()
            elif self._concurrent_mode == 2:
                g = gevent.spawn(self.consumer.keep_circulating(1)(self.consumer._shedual_task), )
                ConsumersManager.schedulal_thread_to_be_join.append(g)
            elif self._concurrent_mode == 3:
                g = eventlet.spawn(self.consumer.keep_circulating(1)(self.consumer._shedual_task), )
                ConsumersManager.schedulal_thread_to_be_join.append(g) 
开发者ID:ydf0509,项目名称:distributed_framework,代码行数:18,代码来源:base_consumer.py

示例8: spawn

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def spawn(*args, **kwargs):
        def _launch(func, *args, **kwargs):
            # mimic gevent's default raise_error=False behaviour
            # by not propergating an exception to the joiner.
            try:
                func(*args, **kwargs)
            except greenlet.GreenletExit:
                pass
            except:
                # log uncaught exception.
                # note: this is an intentional divergence from gevent
                # behaviour.  gevent silently ignores such exceptions.
                LOG.error('hub: uncaught exception: %s',
                          traceback.format_exc())

        return eventlet.spawn(_launch, *args, **kwargs) 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:18,代码来源:hub.py

示例9: __init__

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def __init__(self, listen_info, handle=None, backlog=None,
                     spawn='default', **ssl_args):
            assert backlog is None
            assert spawn == 'default'

            if ':' in listen_info[0]:
                self.server = eventlet.listen(listen_info,
                                              family=socket.AF_INET6)
            else:
                self.server = eventlet.listen(listen_info)
            if ssl_args:
                def wrap_and_handle(sock, addr):
                    ssl_args.setdefault('server_side', True)
                    handle(ssl.wrap_socket(sock, **ssl_args), addr)

                self.handle = wrap_and_handle
            else:
                self.handle = handle 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:20,代码来源:hub.py

示例10: _eventlet_serve

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def _eventlet_serve(sock, handle, concurrency):
    """
    Serve requests forever.

    This code is nearly identical to ``eventlet.convenience.serve`` except
    that it attempts to join the pool at the end, which allows for gunicorn
    graceful shutdowns.
    """
    pool = eventlet.greenpool.GreenPool(concurrency)
    server_gt = eventlet.greenthread.getcurrent()

    while True:
        try:
            conn, addr = sock.accept()
            gt = pool.spawn(handle, conn, addr)
            gt.link(_eventlet_stop, server_gt, conn)
            conn, addr, gt = None, None, None
        except eventlet.StopServe:
            pool.waitall()
            return 
开发者ID:chalasr,项目名称:Flask-P2P,代码行数:22,代码来源:geventlet.py

示例11: spawn

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def spawn(func, *args, **kwargs):
    """Passthrough method for eventlet.spawn.

    This utility exists so that it can be stubbed for testing without
    interfering with the service spawns.

    It will also grab the context from the threadlocal store and add it to
    the store on the new thread.  This allows for continuity in logging the
    context when using this method to spawn a new thread.
    """
    _context = common_context.get_current()

    @functools.wraps(func)
    def context_wrapper(*args, **kwargs):
        # NOTE: If update_store is not called after spawn it won't be
        # available for the logger to pull from threadlocal storage.
        if _context is not None:
            _context.update_store()
        return func(*args, **kwargs)

    return eventlet.spawn(context_wrapper, *args, **kwargs) 
开发者ID:openstack,项目名称:masakari,代码行数:23,代码来源:utils.py

示例12: spawn_n

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def spawn_n(func, *args, **kwargs):
    """Passthrough method for eventlet.spawn_n.

    This utility exists so that it can be stubbed for testing without
    interfering with the service spawns.

    It will also grab the context from the threadlocal store and add it to
    the store on the new thread.  This allows for continuity in logging the
    context when using this method to spawn a new thread.
    """
    _context = common_context.get_current()

    @functools.wraps(func)
    def context_wrapper(*args, **kwargs):
        # NOTE: If update_store is not called after spawn_n it won't be
        # available for the logger to pull from threadlocal storage.
        if _context is not None:
            _context.update_store()
        func(*args, **kwargs)

    eventlet.spawn_n(context_wrapper, *args, **kwargs) 
开发者ID:openstack,项目名称:masakari,代码行数:23,代码来源:utils.py

示例13: _child_wait_for_exit_or_signal

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def _child_wait_for_exit_or_signal(self, launcher):
        status = 0
        signo = 0

        # NOTE(johannes): All exceptions are caught to ensure this
        # doesn't fallback into the loop spawning children. It would
        # be bad for a child to spawn more children.
        try:
            launcher.wait()
        except SignalExit as exc:
            signame = self.signal_handler.signals_to_name[exc.signo]
            LOG.info('Child caught %s, handling', signame)
            status = exc.code
            signo = exc.signo
        except SystemExit as exc:
            launcher.stop()
            status = exc.code
        except BaseException:
            launcher.stop()
            LOG.exception('Unhandled exception')
            status = 2

        return status, signo 
开发者ID:openstack,项目名称:oslo.service,代码行数:25,代码来源:service.py

示例14: test_execute_with_cancel_action_plan

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def test_execute_with_cancel_action_plan(self, mock_eventlet_spawn):
        action_plan = obj_utils.create_test_action_plan(
            self.context, audit_id=self.audit.id,
            strategy_id=self.strategy.id,
            state=objects.action_plan.State.CANCELLING)

        action = obj_utils.create_test_action(
            self.context, action_plan_id=action_plan.id,
            state=objects.action.State.ONGOING,
            action_type='nop',
            input_parameters={'message': 'hello World'})
        action_container = tflow.TaskFlowActionContainer(
            db_action=action,
            engine=self.engine)

        def empty_test():
            pass
        et = eventlet.spawn(empty_test)
        mock_eventlet_spawn.return_value = et
        action_container.execute()
        et.kill.assert_called_with() 
开发者ID:openstack,项目名称:watcher,代码行数:23,代码来源:test_taskflow_action_container.py

示例15: _check_jobs

# 需要导入模块: import eventlet [as 别名]
# 或者: from eventlet import spawn [as 别名]
def _check_jobs(self):
        LOG.debug("Checking jobs")
        jobs = self._jobs.copy()
        job_nr = len(jobs)
        spawned = 0
        now = timeutils.utcnow()
        if job_nr:
            for job in jobs:
                if jobs[job].should_run(now):
                    LOG.debug("Spawning job %s" % job)
                    eventlet.spawn(jobs[job].start, now, self._queue)
                    spawned += 1

        done = timeutils.utcnow()
        delta = done - now
        LOG.debug("Spawned %(jobs)d jobs in %(seconds)d seconds" % {
            "seconds": delta.seconds,
            "jobs": spawned}) 
开发者ID:cloudbase,项目名称:coriolis,代码行数:20,代码来源:cron.py


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