From d260744773c443f3449e044bfabbe9357b7a3cb5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 17 Feb 2016 11:02:09 +0100 Subject: [PATCH] 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 --- oslo_messaging/_executors/impl_aioeventlet.py | 74 ------------------- .../tests/executors/test_executor.py | 64 +--------------- requirements.txt | 4 - setup.cfg | 1 - 4 files changed, 2 insertions(+), 141 deletions(-) delete mode 100644 oslo_messaging/_executors/impl_aioeventlet.py diff --git a/oslo_messaging/_executors/impl_aioeventlet.py b/oslo_messaging/_executors/impl_aioeventlet.py deleted file mode 100644 index abd899ef4..000000000 --- a/oslo_messaging/_executors/impl_aioeventlet.py +++ /dev/null @@ -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 diff --git a/oslo_messaging/tests/executors/test_executor.py b/oslo_messaging/tests/executors/test_executor.py index 75b4c4724..d6f7f2c4e 100644 --- a/oslo_messaging/tests/executors/test_executor.py +++ b/oslo_messaging/tests/executors/test_executor.py @@ -17,27 +17,9 @@ import threading import time -# eventlet 0.16 with monkey patching does not work yet on Python 3, -# so make aioeventlet, eventlet and trollius import optional -try: - import aioeventlet -except ImportError: - aioeventlet = None -try: - import eventlet -except ImportError: - eventlet = None +from six.moves import mock 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 try: from oslo_messaging._executors import impl_eventlet @@ -46,7 +28,6 @@ except ImportError: from oslo_messaging._executors import impl_thread from oslo_messaging import dispatcher as dispatcher_base from oslo_messaging.tests import utils as test_utils -from six.moves import mock load_tests = testscenarios.load_tests_apply_scenarios @@ -61,10 +42,6 @@ class TestExecutor(test_utils.BaseTestCase): if impl_eventlet is not None: impl.append( ('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) @staticmethod @@ -75,48 +52,13 @@ class TestExecutor(test_utils.BaseTestCase): return thread 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: blocking_class = impl_blocking.BlockingExecutor else: blocking_class = None is_blocking = (self.executor == blocking_class) - if is_aioeventlet: - 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: + if is_blocking: def run_executor(executor): executor.start() executor.execute() @@ -148,8 +90,6 @@ class TestExecutor(test_utils.BaseTestCase): result = executor_callback(self.endpoint, incoming.ctxt, incoming.message) - if is_aioeventlet: - event.send() self.result = result return result diff --git a/requirements.txt b/requirements.txt index c09392bfd..ef900b842 100644 --- a/requirements.txt +++ b/requirements.txt @@ -44,7 +44,3 @@ retrying!=1.3.0,>=1.2.3 # Apache-2.0 # middleware 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 diff --git a/setup.cfg b/setup.cfg index 99b42ad44..ee8881582 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,6 @@ oslo.messaging.drivers = pika = oslo_messaging._drivers.impl_pika:PikaDriver oslo.messaging.executors = - aioeventlet = oslo_messaging._executors.impl_aioeventlet:AsyncioEventletExecutor blocking = oslo_messaging._executors.impl_blocking:BlockingExecutor eventlet = oslo_messaging._executors.impl_eventlet:EventletExecutor threading = oslo_messaging._executors.impl_thread:ThreadExecutor