本文整理汇总了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())
示例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)
示例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)
示例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)
示例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.")
示例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)
示例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)
示例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)
示例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
示例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
示例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.")
示例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
示例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.")
示例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
示例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