]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
ioloop: Disallow non-asyncio IOLoops on python 3
authorBen Darnell <ben@bendarnell.com>
Mon, 23 Oct 2017 02:26:55 +0000 (22:26 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 5 Nov 2017 20:09:50 +0000 (15:09 -0500)
.travis.yml
tornado/ioloop.py
tornado/test/ioloop_test.py
tox.ini

index cae048f80bb64a7f8f5f1fee9fc633b9bc752239..2c08bc9d2958dddc59bb460634eb5cc5e22428da 100644 (file)
@@ -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
index e587d0f336ce4e01c6223029ff600302500c8883..c950a89d3143cf3433b9f00e7896aa6a1bd4c0dd 100644 (file)
@@ -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()`.
index e76fb819ee4e1998b26c74e900631f5064d305e1..903383abda68f64e8a6ab230b15a2ed8ed2705a3 100644 (file)
@@ -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 11ba0572569e3f63e397d4429967838e3548c43e..376abaee62826cddc5434c0ff48f02f6682c46f7 100644 (file)
--- 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.