Remove aioeventlet executor
I wrote the aioeventlet executor as a first step to replace eventlet with trollius in OpenStack. Sadly, the project of replacing eventlet with something else (trollius, threads or whatever) looks to be stuck because of various reasons. See the spec: "Replace eventlet + monkey-patching with ??" https://review.openstack.org/#/c/164035/ Recently, I deprecated the trollius project in favor of asyncio: http://trollius.readthedocs.org/deprecated.html Since I abandonned my project to replace eventlet with trollius, I now propose to remove the unused aioeventlet executor from Oslo Messaging to simplify the code and remove unused dependencies (especially trollius). Since the aioeventlet executor is not used by any application, it's safe to remove it. Removing the executor removes trollius and aioeventlet dependencies. ... The executor may come back "later" when the first OpenStack service will start to drop Python 2 support. For more information on asyncio in OpenStack, see: http://aioeventlet.readthedocs.org/openstack.html Note: the executor was added by the change I7a78ed998719a703077232726f66d882463b1297. Change-Id: I10d8d7d4134b32e4fc0badfa15e9ffb005910139
This commit is contained in:
parent
b80fdc850d
commit
d260744773
@ -1,74 +0,0 @@
|
|||||||
# Copyright 2014 eNovance.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
import aioeventlet
|
|
||||||
import trollius
|
|
||||||
|
|
||||||
from oslo_messaging._executors import impl_eventlet
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncioEventletExecutor(impl_eventlet.EventletExecutor):
|
|
||||||
|
|
||||||
"""A message executor which integrates with eventlet and trollius.
|
|
||||||
|
|
||||||
The executor is based on eventlet executor and so is compatible with it.
|
|
||||||
The executor supports trollius coroutines, explicit asynchronous
|
|
||||||
programming, in addition to eventlet greenthreads, implicit asynchronous
|
|
||||||
programming.
|
|
||||||
|
|
||||||
To use the executor, an aioeventlet event loop must the running in the
|
|
||||||
thread executing the executor (usually the main thread). Example of code to
|
|
||||||
setup and run an aioeventlet event loop for the executor (in the main
|
|
||||||
thread)::
|
|
||||||
|
|
||||||
import aioeventlet
|
|
||||||
import trollius
|
|
||||||
|
|
||||||
policy = aioeventlet.EventLoopPolicy()
|
|
||||||
trollius.set_event_loop_policy(policy)
|
|
||||||
|
|
||||||
def run_loop(loop):
|
|
||||||
loop.run_forever()
|
|
||||||
loop.close()
|
|
||||||
|
|
||||||
# Get the aioeventlet event loop (create it if needed)
|
|
||||||
loop = trollius.get_event_loop()
|
|
||||||
|
|
||||||
# run the event loop in a new greenthread,
|
|
||||||
# close it when it is done
|
|
||||||
eventlet.spawn(run_loop, loop)
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, conf, listener, dispatcher):
|
|
||||||
super(AsyncioEventletExecutor, self).__init__(conf, listener,
|
|
||||||
dispatcher)
|
|
||||||
self._loop = None
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
# check that the event loop is an aioeventlet event loop
|
|
||||||
loop = trollius.get_event_loop()
|
|
||||||
if not isinstance(loop, aioeventlet.EventLoop):
|
|
||||||
raise RuntimeError("need an aioeventlet event loop")
|
|
||||||
self._loop = loop
|
|
||||||
|
|
||||||
super(AsyncioEventletExecutor, self).start()
|
|
||||||
|
|
||||||
def _coroutine_wrapper(self, func, *args, **kw):
|
|
||||||
result = func(*args, **kw)
|
|
||||||
if trollius.iscoroutine(result):
|
|
||||||
result = aioeventlet.yield_future(result, loop=self._loop)
|
|
||||||
return result
|
|
||||||
|
|
||||||
_executor_callback = _coroutine_wrapper
|
|
@ -17,27 +17,9 @@
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# eventlet 0.16 with monkey patching does not work yet on Python 3,
|
from six.moves import mock
|
||||||
# so make aioeventlet, eventlet and trollius import optional
|
|
||||||
try:
|
|
||||||
import aioeventlet
|
|
||||||
except ImportError:
|
|
||||||
aioeventlet = None
|
|
||||||
try:
|
|
||||||
import eventlet
|
|
||||||
except ImportError:
|
|
||||||
eventlet = None
|
|
||||||
import testscenarios
|
import testscenarios
|
||||||
try:
|
|
||||||
import trollius
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
from oslo_messaging._executors import impl_aioeventlet
|
|
||||||
except ImportError:
|
|
||||||
impl_aioeventlet = None
|
|
||||||
from oslo_messaging._executors import impl_blocking
|
from oslo_messaging._executors import impl_blocking
|
||||||
try:
|
try:
|
||||||
from oslo_messaging._executors import impl_eventlet
|
from oslo_messaging._executors import impl_eventlet
|
||||||
@ -46,7 +28,6 @@ except ImportError:
|
|||||||
from oslo_messaging._executors import impl_thread
|
from oslo_messaging._executors import impl_thread
|
||||||
from oslo_messaging import dispatcher as dispatcher_base
|
from oslo_messaging import dispatcher as dispatcher_base
|
||||||
from oslo_messaging.tests import utils as test_utils
|
from oslo_messaging.tests import utils as test_utils
|
||||||
from six.moves import mock
|
|
||||||
|
|
||||||
load_tests = testscenarios.load_tests_apply_scenarios
|
load_tests = testscenarios.load_tests_apply_scenarios
|
||||||
|
|
||||||
@ -61,10 +42,6 @@ class TestExecutor(test_utils.BaseTestCase):
|
|||||||
if impl_eventlet is not None:
|
if impl_eventlet is not None:
|
||||||
impl.append(
|
impl.append(
|
||||||
('eventlet', dict(executor=impl_eventlet.EventletExecutor)))
|
('eventlet', dict(executor=impl_eventlet.EventletExecutor)))
|
||||||
if impl_aioeventlet is not None:
|
|
||||||
impl.append(
|
|
||||||
('aioeventlet',
|
|
||||||
dict(executor=impl_aioeventlet.AsyncioEventletExecutor)))
|
|
||||||
cls.scenarios = testscenarios.multiply_scenarios(impl)
|
cls.scenarios = testscenarios.multiply_scenarios(impl)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -75,48 +52,13 @@ class TestExecutor(test_utils.BaseTestCase):
|
|||||||
return thread
|
return thread
|
||||||
|
|
||||||
def _create_dispatcher(self):
|
def _create_dispatcher(self):
|
||||||
if impl_aioeventlet is not None:
|
|
||||||
aioeventlet_class = impl_aioeventlet.AsyncioEventletExecutor
|
|
||||||
else:
|
|
||||||
aioeventlet_class = None
|
|
||||||
is_aioeventlet = (self.executor == aioeventlet_class)
|
|
||||||
|
|
||||||
if impl_blocking is not None:
|
if impl_blocking is not None:
|
||||||
blocking_class = impl_blocking.BlockingExecutor
|
blocking_class = impl_blocking.BlockingExecutor
|
||||||
else:
|
else:
|
||||||
blocking_class = None
|
blocking_class = None
|
||||||
is_blocking = (self.executor == blocking_class)
|
is_blocking = (self.executor == blocking_class)
|
||||||
|
|
||||||
if is_aioeventlet:
|
if is_blocking:
|
||||||
policy = aioeventlet.EventLoopPolicy()
|
|
||||||
trollius.set_event_loop_policy(policy)
|
|
||||||
self.addCleanup(trollius.set_event_loop_policy, None)
|
|
||||||
|
|
||||||
def run_loop(loop):
|
|
||||||
loop.run_forever()
|
|
||||||
loop.close()
|
|
||||||
trollius.set_event_loop(None)
|
|
||||||
|
|
||||||
def run_executor(executor):
|
|
||||||
# create an event loop in the executor thread
|
|
||||||
loop = trollius.new_event_loop()
|
|
||||||
trollius.set_event_loop(loop)
|
|
||||||
eventlet.spawn(run_loop, loop)
|
|
||||||
|
|
||||||
# run the executor
|
|
||||||
executor.start()
|
|
||||||
executor.wait()
|
|
||||||
|
|
||||||
# stop the event loop: run_loop() will close it
|
|
||||||
loop.stop()
|
|
||||||
|
|
||||||
@trollius.coroutine
|
|
||||||
def simple_coroutine(value):
|
|
||||||
raise trollius.Return(value)
|
|
||||||
|
|
||||||
endpoint = mock.MagicMock(return_value=simple_coroutine('result'))
|
|
||||||
event = eventlet.event.Event()
|
|
||||||
elif is_blocking:
|
|
||||||
def run_executor(executor):
|
def run_executor(executor):
|
||||||
executor.start()
|
executor.start()
|
||||||
executor.execute()
|
executor.execute()
|
||||||
@ -148,8 +90,6 @@ class TestExecutor(test_utils.BaseTestCase):
|
|||||||
result = executor_callback(self.endpoint,
|
result = executor_callback(self.endpoint,
|
||||||
incoming.ctxt,
|
incoming.ctxt,
|
||||||
incoming.message)
|
incoming.message)
|
||||||
if is_aioeventlet:
|
|
||||||
event.send()
|
|
||||||
self.result = result
|
self.result = result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -44,7 +44,3 @@ retrying!=1.3.0,>=1.2.3 # Apache-2.0
|
|||||||
|
|
||||||
# middleware
|
# middleware
|
||||||
oslo.middleware>=3.0.0 # Apache-2.0
|
oslo.middleware>=3.0.0 # Apache-2.0
|
||||||
|
|
||||||
# needed by the aioeventlet executor
|
|
||||||
aioeventlet>=0.4 # Apache-2.0
|
|
||||||
trollius>=1.0 # Apache-2.0
|
|
||||||
|
@ -40,7 +40,6 @@ oslo.messaging.drivers =
|
|||||||
pika = oslo_messaging._drivers.impl_pika:PikaDriver
|
pika = oslo_messaging._drivers.impl_pika:PikaDriver
|
||||||
|
|
||||||
oslo.messaging.executors =
|
oslo.messaging.executors =
|
||||||
aioeventlet = oslo_messaging._executors.impl_aioeventlet:AsyncioEventletExecutor
|
|
||||||
blocking = oslo_messaging._executors.impl_blocking:BlockingExecutor
|
blocking = oslo_messaging._executors.impl_blocking:BlockingExecutor
|
||||||
eventlet = oslo_messaging._executors.impl_eventlet:EventletExecutor
|
eventlet = oslo_messaging._executors.impl_eventlet:EventletExecutor
|
||||||
threading = oslo_messaging._executors.impl_thread:ThreadExecutor
|
threading = oslo_messaging._executors.impl_thread:ThreadExecutor
|
||||||
|
Loading…
Reference in New Issue
Block a user