]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
ioloop: Make PollIOLoop separately configurable 2062/head
authorBen Darnell <ben@bendarnell.com>
Sat, 27 May 2017 23:11:35 +0000 (19:11 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 27 May 2017 23:11:35 +0000 (19:11 -0400)
This makes it possible to construct a PollIOLoop even when the default
IOLoop is configured to something else.

tornado/ioloop.py
tornado/platform/twisted.py
tornado/test/twisted_test.py

index 5997cef667ca7a43c6f05ba46872a3f658775a16..f4d4642077d45632d058db7d4ef6de44a7effbf5 100644 (file)
@@ -249,15 +249,7 @@ class IOLoop(Configurable):
 
     @classmethod
     def configurable_default(cls):
-        if hasattr(select, "epoll"):
-            from tornado.platform.epoll import EPollIOLoop
-            return EPollIOLoop
-        if hasattr(select, "kqueue"):
-            # Python 2.6+ on BSD or Mac
-            from tornado.platform.kqueue import KQueueIOLoop
-            return KQueueIOLoop
-        from tornado.platform.select import SelectIOLoop
-        return SelectIOLoop
+        return PollIOLoop
 
     def initialize(self, make_current=None):
         if make_current is None:
@@ -722,6 +714,22 @@ class PollIOLoop(IOLoop):
                          lambda fd, events: self._waker.consume(),
                          self.READ)
 
+    @classmethod
+    def configurable_base(cls):
+        return PollIOLoop
+
+    @classmethod
+    def configurable_default(cls):
+        if hasattr(select, "epoll"):
+            from tornado.platform.epoll import EPollIOLoop
+            return EPollIOLoop
+        if hasattr(select, "kqueue"):
+            # Python 2.6+ on BSD or Mac
+            from tornado.platform.kqueue import KQueueIOLoop
+            return KQueueIOLoop
+        from tornado.platform.select import SelectIOLoop
+        return SelectIOLoop
+
     def close(self, all_fds=False):
         self._closing = True
         self.remove_handler(self._waker.fileno())
index 79608e5fb9401e356b1a5d2a50b00632ecdd402b..7c337e8a59e042c16962eb449cc9d1130bf80f86 100644 (file)
@@ -382,6 +382,8 @@ class _FD(object):
             self.handler(self.fileobj, tornado.ioloop.IOLoop.ERROR)
             self.lost = True
 
+    writeConnectionLost = readConnectionLost = connectionLost
+
     def logPrefix(self):
         return ''
 
index 10afebb7bcce1a7dea76ec7389b6fa6de84c2b8a..4b88eca862df0f18afbedf74c6b495b98196fb48 100644 (file)
@@ -32,9 +32,8 @@ from tornado.escape import utf8
 from tornado import gen
 from tornado.httpclient import AsyncHTTPClient
 from tornado.httpserver import HTTPServer
-from tornado.ioloop import IOLoop
+from tornado.ioloop import IOLoop, PollIOLoop
 from tornado.platform.auto import set_close_exec
-from tornado.platform.select import SelectIOLoop
 from tornado.testing import bind_unused_port
 from tornado.test.util import unittest
 from tornado.util import import_object, PY3
@@ -690,7 +689,7 @@ if have_twisted:
 
 if have_twisted:
     class LayeredTwistedIOLoop(TwistedIOLoop):
-        """Layers a TwistedIOLoop on top of a TornadoReactor on a SelectIOLoop.
+        """Layers a TwistedIOLoop on top of a TornadoReactor on a PollIOLoop.
 
         This is of course silly, but is useful for testing purposes to make
         sure we're implementing both sides of the various interfaces
@@ -698,10 +697,7 @@ if have_twisted:
         of the whole stack.
         """
         def initialize(self, **kwargs):
-            # When configured to use LayeredTwistedIOLoop we can't easily
-            # get the next-best IOLoop implementation, so use the lowest common
-            # denominator.
-            self.real_io_loop = SelectIOLoop(make_current=False)  # type: ignore
+            self.real_io_loop = PollIOLoop(make_current=False)  # type: ignore
             reactor = self.real_io_loop.run_sync(gen.coroutine(TornadoReactor))
             super(LayeredTwistedIOLoop, self).initialize(reactor=reactor, **kwargs)
             self.add_callback(self.make_current)