當前位置: 首頁>>代碼示例>>Python>>正文


Python greenlet.GreenletExit方法代碼示例

本文整理匯總了Python中greenlet.GreenletExit方法的典型用法代碼示例。如果您正苦於以下問題:Python greenlet.GreenletExit方法的具體用法?Python greenlet.GreenletExit怎麽用?Python greenlet.GreenletExit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在greenlet的用法示例。


在下文中一共展示了greenlet.GreenletExit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _eventlet_stop

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def _eventlet_stop(client, server, conn):
    """
    Stop a greenlet handling a request and close its connection.

    This code is lifted from eventlet so as not to depend on undocumented
    functions in the library.
    """
    try:
        try:
            client.wait()
        finally:
            conn.close()
    except greenlet.GreenletExit:
        pass
    except Exception:
        greenthread.kill(server, *sys.exc_info()) 
開發者ID:jpush,項目名稱:jbox,代碼行數:18,代碼來源:geventlet.py

示例2: kill

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def kill(greenlet, exception=GreenletExit):
    """
    Kill greenlet asynchronously. The current greenlet is not unscheduled.

    .. note::

        The method :meth:`Greenlet.kill` method does the same and
        more (and the same caveats listed there apply here). However, the MAIN
        greenlet - the one that exists initially - does not have a
        ``kill()`` method, and neither do any created with :func:`spawn_raw`,
        so you have to use this function.

    .. versionchanged:: 1.1a2
        If the ``greenlet`` has a :meth:`kill <Greenlet.kill>` method, calls it. This prevents a
        greenlet from being switched to for the first time after it's been
        killed but not yet executed.
    """
    if not greenlet.dead:
        if hasattr(greenlet, 'kill'):
            # dealing with gevent.greenlet.Greenlet. Use it, especially
            # to avoid allowing one to be switched to for the first time
            # after it's been killed
            greenlet.kill(exception=exception, block=False)
        else:
            get_hub().loop.run_callback(greenlet.throw, exception) 
開發者ID:leancloud,項目名稱:satori,代碼行數:27,代碼來源:hub.py

示例3: spawn

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [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

示例4: spawn_after

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def spawn_after(seconds, *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_after(seconds, _launch, *args, **kwargs) 
開發者ID:OpenState-SDN,項目名稱:ryu,代碼行數:18,代碼來源:hub.py

示例5: wait

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def wait(self):
        """Block, until the server has stopped.

        Waits on the server's eventlet to finish, then returns.

        :returns: None

        """
        try:
            if self._server is not None:
                self._server.wait()
        except greenlet.GreenletExit:
            LOG.info("WSGI server has stopped.") 
開發者ID:openstack,項目名稱:ec2-api,代碼行數:15,代碼來源:wsgi.py

示例6: _query_finished

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def _query_finished(self, gquery):
        self.queries_lock.acquire()
        self.queries.pop(gquery.uuid, None)
        self.queries_lock.release()

        try:
            result = gquery.get()

        except:
            self.store.release_all(gquery.uuid)
            LOG.exception('Query finished with exception')
            return

        if isinstance(result, greenlet.GreenletExit):
            self.store.release_all(gquery.uuid) 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:17,代碼來源:queryprocessor.py

示例7: test_queryprocessor_1

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def test_queryprocessor_1(self, query_mock):
        comm = comm_mock.comm_factory({})
        store = traced_mock.store_factory()

        qp = minemeld.traced.queryprocessor.QueryProcessor(comm, store)

        self.assertEqual(
            comm.rpc_server_channels[0]['name'],
            minemeld.traced.queryprocessor.QUERY_QUEUE
        )
        self.assertEqual(
            comm.rpc_server_channels[0]['allowed_methods'],
            ['query', 'kill_query']
        )

        qp.query('uuid-test-1', "test query")
        self.assertEqual(len(traced_mock.MOCK_QUERIES), 1)

        qp.query('uuid-test-2', "test query")
        self.assertEqual(len(traced_mock.MOCK_QUERIES), 2)

        gevent.sleep(0)

        traced_mock.MOCK_QUERIES[0].finish_event.set()

        gevent.sleep(0)

        qp.stop()
        gevent.sleep(0)
        gevent.sleep(0)

        self.assertEqual(traced_mock.MOCK_QUERIES[0].get(), None)
        self.assertIsInstance(
            traced_mock.MOCK_QUERIES[1].get(),
            greenlet.GreenletExit
        )
        self.assertNotIn('uuid-test-1', store.release_alls)
        self.assertIn('uuid-test-2', store.release_alls) 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:40,代碼來源:test_traced_queryprocessor.py

示例8: test_queryprocessor_3

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def test_queryprocessor_3(self, query_mock):
        comm = comm_mock.comm_factory({})
        store = traced_mock.store_factory()

        qp = minemeld.traced.queryprocessor.QueryProcessor(comm, store)

        self.assertEqual(
            comm.rpc_server_channels[0]['name'],
            minemeld.traced.queryprocessor.QUERY_QUEUE
        )
        self.assertEqual(
            comm.rpc_server_channels[0]['allowed_methods'],
            ['query', 'kill_query']
        )

        qp.query('uuid-test-1', "test query")
        gevent.sleep(0)

        qp.kill_query('uuid-test-1')
        gevent.sleep(0)

        self.assertIsInstance(
            traced_mock.MOCK_QUERIES[0].get(),
            greenlet.GreenletExit
        )
        self.assertEqual(
            len(qp.queries),
            0
        )
        self.assertIn('uuid-test-1', store.release_alls)

        qp.stop()
        gevent.sleep(0) 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:35,代碼來源:test_traced_queryprocessor.py

示例9: _arp_loop

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def _arp_loop(self):
        try:
            with contextlib.closing(
                socket.socket(
                    socket.AF_PACKET, socket.SOCK_RAW,
                    socket.htons(ether.ETH_TYPE_ARP))) as packet_socket:
                packet_socket.bind((self.interface.device_name,
                                    socket.htons(ether.ETH_TYPE_ARP),
                                    socket.PACKET_BROADCAST,
                                    arp.ARP_HW_TYPE_ETHERNET,
                                    mac_lib.BROADCAST))
                self._arp_loop_socket(packet_socket)
        except greenlet.GreenletExit:
            # suppress thread.kill exception
            pass 
開發者ID:OpenState-SDN,項目名稱:ryu,代碼行數:17,代碼來源:sample_router.py

示例10: joinall

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def joinall(threads):
        for t in threads:
            # this try-except is necessary when killing an inactive
            # greenthread
            try:
                t.wait()
            except greenlet.GreenletExit:
                pass 
開發者ID:OpenState-SDN,項目名稱:ryu,代碼行數:10,代碼來源:hub.py

示例11: wait

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def wait(self):
        """Block, until the server has stopped.

        Waits on the server's eventlet to finish, then returns.

        :returns: None

        """
        try:
            if self._server is not None:
                self._pool.waitall()
                self._server.wait()
        except greenlet.GreenletExit:
            LOG.info("WSGI server has stopped.") 
開發者ID:openstack,項目名稱:masakari,代碼行數:16,代碼來源:wsgi.py

示例12: wait

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def wait(self, timeout, exception):
        with eventlet.Timeout(timeout, exception):
            try:
                self.daemon.wait()
            except greenlet.GreenletExit:
                return True 
開發者ID:openstack,項目名稱:dragonflow,代碼行數:8,代碼來源:app_testing_objects.py

示例13: wait

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def wait(self):
        """Block, until the server has stopped.

        Waits on the server's eventlet to finish, then returns.

        :returns: None

        """
        try:
            if self._server is not None:
                num = self._pool.running()
                LOG.debug("Waiting WSGI server to finish %d requests.", num)
                self._pool.waitall()
        except greenlet.GreenletExit:
            LOG.info("WSGI server has stopped.") 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:17,代碼來源:wsgi.py

示例14: wait

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def wait(self):
        """Wait until all servers have completed running."""
        try:
            self.pool.waitall()
        except KeyboardInterrupt:
            pass
        except greenlet.GreenletExit:
            pass 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:10,代碼來源:eventlet_service.py

示例15: _run

# 需要導入模塊: import greenlet [as 別名]
# 或者: from greenlet import GreenletExit [as 別名]
def _run(self, application, socket):
        """Start a WSGI server with a new green thread pool."""
        try:
            eventlet.wsgi.server(socket, application, debug=False)
        except greenlet.GreenletExit:
            # Wait until all servers have completed running
            pass 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:9,代碼來源:eventlet_service.py


注:本文中的greenlet.GreenletExit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。