Python greenlet.GreenletExit() Examples
The following are 23
code examples of greenlet.GreenletExit().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
greenlet
, or try the search function
.
Example #1
Source File: geventlet.py From jbox with MIT License | 6 votes |
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())
Example #2
Source File: hub.py From PokemonGo-DesktopMap with MIT License | 6 votes |
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)
Example #3
Source File: hub.py From satori with Apache License 2.0 | 6 votes |
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)
Example #4
Source File: hub.py From PokemonGo-DesktopMap with MIT License | 6 votes |
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)
Example #5
Source File: hub.py From ryu with Apache License 2.0 | 6 votes |
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)
Example #6
Source File: hub.py From ryu with Apache License 2.0 | 6 votes |
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)
Example #7
Source File: geventlet.py From Flask-P2P with MIT License | 6 votes |
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())
Example #8
Source File: service.py From vxfld with GNU General Public License v2.0 | 5 votes |
def _stop_checker(self, green_thread): """ Propagates exceptions to the run green thread. """ try: green_thread.wait() except greenlet.GreenletExit: # pylint: disable=no-member pass except Exception: # pylint: disable=broad-except eventlet.kill(self.__run_gt, *sys.exc_info())
Example #9
Source File: wsgi.py From ec2-api with Apache License 2.0 | 5 votes |
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.")
Example #10
Source File: netlink.py From vxfld with GNU General Public License v2.0 | 5 votes |
def __stop_checker(self, green_thread): """ Propagates exceptions to the dispatcher green thread. """ ifindex = None try: ifindex = green_thread.wait() except greenlet.GreenletExit: # pylint: disable=no-member pass except Exception: # pylint: disable=broad-except eventlet.kill(self.dispatcher_gt, *sys.exc_info()) self.__running.remove(ifindex) self.__intfevent.put(ifindex)
Example #11
Source File: green_thread_executor.py From karbor with Apache License 2.0 | 5 votes |
def shutdown(self): for op_id, gt in self._operation_thread_map.items(): if gt is None: continue gt.cancel() try: gt.wait() # wait untile the thread finishes its work except (greenlet.GreenletExit, Exception): pass self._operation_thread_map = {}
Example #12
Source File: hub.py From PhonePi_SampleServer with MIT License | 5 votes |
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. .. caution:: Use care when killing greenlets. If they are not prepared for exceptions, this could result in corrupted state. .. 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)
Example #13
Source File: gevent_extractor.py From trains with Apache License 2.0 | 5 votes |
def _job_wrapper(self, job): def _job(name): result = None try: result = job(name) except greenlet.GreenletExit: self._exited_greenlets += 1 except Exception: e = sys.exc_info()[1] logger.error('Extracting "{0}", got: {1}'.format(name, e)) return result return _job
Example #14
Source File: eventlet_service.py From oslo.service with Apache License 2.0 | 5 votes |
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
Example #15
Source File: eventlet_service.py From oslo.service with Apache License 2.0 | 5 votes |
def wait(self): """Wait until all servers have completed running.""" try: self.pool.waitall() except KeyboardInterrupt: pass except greenlet.GreenletExit: pass
Example #16
Source File: wsgi.py From oslo.service with Apache License 2.0 | 5 votes |
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.")
Example #17
Source File: app_testing_objects.py From dragonflow with Apache License 2.0 | 5 votes |
def wait(self, timeout, exception): with eventlet.Timeout(timeout, exception): try: self.daemon.wait() except greenlet.GreenletExit: return True
Example #18
Source File: wsgi.py From masakari with Apache License 2.0 | 5 votes |
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.")
Example #19
Source File: hub.py From ryu with Apache License 2.0 | 5 votes |
def joinall(threads): for t in threads: # this try-except is necessary when killing an inactive # greenthread try: t.wait() except greenlet.GreenletExit: pass
Example #20
Source File: sample_router.py From ryu with Apache License 2.0 | 5 votes |
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
Example #21
Source File: test_traced_queryprocessor.py From minemeld-core with Apache License 2.0 | 5 votes |
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)
Example #22
Source File: test_traced_queryprocessor.py From minemeld-core with Apache License 2.0 | 5 votes |
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)
Example #23
Source File: queryprocessor.py From minemeld-core with Apache License 2.0 | 5 votes |
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)