From: Ben Darnell Date: Mon, 23 Oct 2017 02:26:55 +0000 (-0400) Subject: ioloop: Disallow non-asyncio IOLoops on python 3 X-Git-Tag: v5.0.0~45^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7d2a152f96c349648f1212c67d05f8aebd027fb;p=thirdparty%2Ftornado.git ioloop: Disallow non-asyncio IOLoops on python 3 --- diff --git a/.travis.yml b/.travis.yml index cae048f80..2c08bc9d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,18 +59,17 @@ script: # run it with nightly cpython. - if [[ $TRAVIS_PYTHON_VERSION != nightly ]]; then export TARGET="-m coverage run $TARGET"; fi - python $TARGET - - python $TARGET --ioloop=tornado.platform.select.SelectIOLoop + - if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then python $TARGET --ioloop=tornado.platform.select.SelectIOLoop; fi - python -O $TARGET - LANG=C python $TARGET - LANG=en_US.utf-8 python $TARGET - if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then python -bb $TARGET; fi - if [[ $TRAVIS_PYTHON_VERSION != pypy* ]]; then python $TARGET --resolver=tornado.netutil.ThreadedResolver; fi - if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then python $TARGET --httpclient=tornado.curl_httpclient.CurlAsyncHTTPClient; fi - - if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then python $TARGET --ioloop=tornado.platform.twisted.TwistedIOLoop; fi - - if [[ $TRAVIS_PYTHON_VERSION == 3.4 || $TRAVIS_PYTHON_VERSION == 3.5 || $TRAVIS_PYTHON_VERSION == 3.6 ]]; then python $TARGET --ioloop=tornado.ioloop.PollIOLoop; fi + - if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then python $TARGET --ioloop=tornado.platform.twisted.TwistedIOLoop; fi - if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then python $TARGET --ioloop=tornado.platform.asyncio.AsyncIOLoop; fi - if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then python $TARGET --resolver=tornado.platform.twisted.TwistedResolver; fi - - if [[ $TRAVIS_PYTHON_VERSION != pypy* ]]; then python $TARGET --ioloop=tornado.ioloop.PollIOLoop --ioloop_time_monotonic; fi + - if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then python $TARGET --ioloop=tornado.ioloop.PollIOLoop --ioloop_time_monotonic; fi #- if [[ $TRAVIS_PYTHON_VERSION != pypy* ]]; then python $TARGET --resolver=tornado.platform.caresresolver.CaresResolver; fi - if [[ $TRAVIS_PYTHON_VERSION != 'pypy3' ]]; then ../nodeps/bin/python -m tornado.test.runtests; fi # make coverage reports for Codecov to find diff --git a/tornado/ioloop.py b/tornado/ioloop.py index e587d0f33..c950a89d3 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -48,7 +48,7 @@ from tornado.concurrent import Future, is_future, chain_future, future_set_exc_i from tornado.log import app_log, gen_log from tornado.platform.auto import set_close_exec, Waker from tornado import stack_context -from tornado.util import PY3, Configurable, errno_from_exception, timedelta_to_seconds, TimeoutError +from tornado.util import PY3, Configurable, errno_from_exception, timedelta_to_seconds, TimeoutError, unicode_type, import_object try: import signal @@ -161,6 +161,18 @@ class IOLoop(Configurable): _current = threading.local() + @classmethod + def configure(cls, impl, **kwargs): + if asyncio is not None: + from tornado.platform.asyncio import BaseAsyncIOLoop + + if isinstance(impl, (str, unicode_type)): + impl = import_object(impl) + if not issubclass(impl, BaseAsyncIOLoop): + raise RuntimeError( + "only AsyncIOLoop is allowed when asyncio is available") + super(IOLoop, cls).configure(impl, **kwargs) + @staticmethod def instance(): """Deprecated alias for `IOLoop.current()`. diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index e76fb819e..903383abd 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -799,6 +799,8 @@ class TestIOLoopConfiguration(unittest.TestCase): 'print(isinstance(IOLoop.current(), PollIOLoop))') self.assertEqual(is_poll, 'True') + @unittest.skipIf(asyncio is not None, + "IOLoop configuration not available") def test_explicit_select(self): # SelectIOLoop can always be configured explicitly. default_class = self.run_python( diff --git a/tox.ini b/tox.ini index 11ba05725..376abaee6 100644 --- a/tox.ini +++ b/tox.ini @@ -27,10 +27,9 @@ envlist = {py2,py3}-curl, # Alternate IOLoops. - {py2,py3}-select, - {py2,py3}-full-twisted, + py2-select, + py2-full-twisted, py2-twistedlayered, - py3-full-poll, py2-full-trollius, # Alternate Resolvers.