]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
All functions that take an IOLoop default to current() instead of instance().
authorBen Darnell <ben@bendarnell.com>
Sun, 3 Mar 2013 00:08:22 +0000 (19:08 -0500)
committerBen Darnell <ben@bendarnell.com>
Sun, 3 Mar 2013 00:08:22 +0000 (19:08 -0500)
This means among other things that it's no longer necessary to pass
IOLoops explicitly in tests.

tornado/autoreload.py
tornado/httpclient.py
tornado/ioloop.py
tornado/iostream.py
tornado/netutil.py
tornado/platform/caresresolver.py
tornado/platform/twisted.py
tornado/process.py
tornado/tcpserver.py
tornado/test/iostream_test.py
tornado/websocket.py

index 4e424878f1f5994a35afd3b5dc87e23c57d2a908..90a8a80272296d82f9490b9fcc124ff8e43fe93d 100644 (file)
@@ -99,7 +99,7 @@ def start(io_loop=None, check_time=500):
     We run on the I/O loop, and restarting is a destructive operation,
     so will terminate any pending requests.
     """
-    io_loop = io_loop or ioloop.IOLoop.instance()
+    io_loop = io_loop or ioloop.IOLoop.current()
     if io_loop in _io_loops:
         return
     _io_loops[io_loop] = True
index c325a63bd0b5ee1f9a62284ca85db10cda3d9f68..a9ac0e70a334e7702cc38b9a29d0cda3b091d8f1 100644 (file)
@@ -131,7 +131,7 @@ class AsyncHTTPClient(Configurable):
         return getattr(cls, attr_name)
 
     def __new__(cls, io_loop=None, force_instance=False, **kwargs):
-        io_loop = io_loop or IOLoop.instance()
+        io_loop = io_loop or IOLoop.current()
         if io_loop in cls._async_clients() and not force_instance:
             return cls._async_clients()[io_loop]
         instance = super(AsyncHTTPClient, cls).__new__(cls, io_loop=io_loop,
index 4fc43baddf723fa80fabeb5089c94cca3c8e3718..a431d5d0c7f220c7e4e3755c0224520a9a52e6f7 100644 (file)
@@ -164,7 +164,7 @@ class IOLoop(Configurable):
     def current():
         current = getattr(IOLoop._current, "instance", None)
         if current is None:
-            raise ValueError("no current IOLoop")
+            return IOLoop.instance()
         return current
 
     def make_current(self):
@@ -733,7 +733,7 @@ class PeriodicCallback(object):
         if callback_time <= 0:
             raise ValueError("Periodic callback must have a positive callback_time")
         self.callback_time = callback_time
-        self.io_loop = io_loop or IOLoop.instance()
+        self.io_loop = io_loop or IOLoop.current()
         self._running = False
         self._timeout = None
 
index 9d9fb7156c75a216d6fed50d25a55ef44e3aa7f6..28bc18f4a8ae6053d2d2bf37d48daa54f47425f9 100644 (file)
@@ -66,7 +66,7 @@ class BaseIOStream(object):
     """
     def __init__(self, io_loop=None, max_buffer_size=104857600,
                  read_chunk_size=4096):
-        self.io_loop = io_loop or ioloop.IOLoop.instance()
+        self.io_loop = io_loop or ioloop.IOLoop.current()
         self.max_buffer_size = max_buffer_size
         self.read_chunk_size = read_chunk_size
         self.error = None
index 46e4227ecda84bc50ffae5eb631a7a0f4757970c..06c88ab61bdbb4b136764745aa5b651ec5c74d45 100644 (file)
@@ -128,7 +128,7 @@ def add_accept_handler(sock, callback, io_loop=None):
     ``IOLoop`` handlers.
     """
     if io_loop is None:
-        io_loop = IOLoop.instance()
+        io_loop = IOLoop.current()
 
     def accept_handler(fd, events):
         while True:
@@ -186,7 +186,7 @@ class Resolver(Configurable):
 
 class ExecutorResolver(Resolver):
     def initialize(self, io_loop=None, executor=None):
-        self.io_loop = io_loop or IOLoop.instance()
+        self.io_loop = io_loop or IOLoop.current()
         self.executor = executor or dummy_executor
 
     @run_on_executor
index 729be3c415de64b6636839df5b301c08b811b128..7442b33c32f7971a51d3b24775444c02e60f866a 100644 (file)
@@ -19,7 +19,7 @@ class CaresResolver(Resolver):
     may default to ``AF_UNSPEC``.
     """
     def initialize(self, io_loop=None):
-        self.io_loop = io_loop or IOLoop.instance()
+        self.io_loop = io_loop or IOLoop.current()
         self.channel = pycares.Channel(sock_state_cb=self._sock_state_cb)
         self.fds = {}
 
index e044701cd6ff3694b17344e6dca1c0b2587ff97c..a95b009fd1c5ea53434cb1803e91d41935545770 100644 (file)
@@ -149,7 +149,7 @@ class TornadoReactor(PosixReactorBase):
     """
     def __init__(self, io_loop=None):
         if not io_loop:
-            io_loop = tornado.ioloop.IOLoop.instance()
+            io_loop = tornado.ioloop.IOLoop.current()
         self._io_loop = io_loop
         self._readers = {}  # map of reader objects to fd
         self._writers = {}  # map of writer objects to fd
@@ -357,7 +357,7 @@ class _TestReactor(TornadoReactor):
 def install(io_loop=None):
     """Install this package as the default Twisted reactor."""
     if not io_loop:
-        io_loop = tornado.ioloop.IOLoop.instance()
+        io_loop = tornado.ioloop.IOLoop.current()
     reactor = TornadoReactor(io_loop)
     from twisted.internet.main import installReactor
     installReactor(reactor)
@@ -504,7 +504,7 @@ class TwistedResolver(Resolver):
     Requires Twisted 12.1 or newer.
     """
     def initialize(self, io_loop=None):
-        self.io_loop = io_loop or IOLoop.instance()
+        self.io_loop = io_loop or IOLoop.current()
         # partial copy of twisted.names.client.createResolver, which doesn't
         # allow for a reactor to be passed in.
         self.reactor = tornado.platform.twisted.TornadoReactor(io_loop)
index 0509eb3a9cb95db0f2515d38641ae4addf1704a0..55481a22c9a53adec42151520a45600d627c5101 100644 (file)
@@ -237,7 +237,7 @@ class Subprocess(object):
         if cls._initialized:
             return
         if io_loop is None:
-            io_loop = ioloop.IOLoop.instance()
+            io_loop = ioloop.IOLoop.current()
         cls._old_sigchld = signal.signal(
             signal.SIGCHLD,
             lambda sig, frame: io_loop.add_callback_from_signal(cls._cleanup))
index 52ed70b1d733dcfa1db79c64b3a673aab9aefbe8..41a5eceab4a2d091475a4af3cf95ef2c29fa949e 100644 (file)
@@ -123,7 +123,7 @@ class TCPServer(object):
         control over the initialization of a multi-process server.
         """
         if self.io_loop is None:
-            self.io_loop = IOLoop.instance()
+            self.io_loop = IOLoop.current()
 
         for sock in sockets:
             self._sockets[sock.fileno()] = sock
index c2e9cab94f478b3a503ca8e74c9531f49d7af765..1aa85a6fa4ee34e64c065c03d283cb62c7343ea0 100644 (file)
@@ -468,10 +468,10 @@ class TestIOStreamWebHTTPS(TestIOStreamWebMixin, AsyncHTTPSTestCase):
 
 class TestIOStream(TestIOStreamMixin, AsyncTestCase):
     def _make_server_iostream(self, connection, **kwargs):
-        return IOStream(connection, io_loop=self.io_loop, **kwargs)
+        return IOStream(connection, **kwargs)
 
     def _make_client_iostream(self, connection, **kwargs):
-        return IOStream(connection, io_loop=self.io_loop, **kwargs)
+        return IOStream(connection, **kwargs)
 
 
 class TestIOStreamSSL(TestIOStreamMixin, AsyncTestCase):
index 235a1102e6356f6cf72b825ecdf871a39c31fa99..b47a37afed7fc5728a1ab3140cb5ee4ecb001897 100644 (file)
@@ -795,7 +795,7 @@ class _WebSocketClientConnection(simple_httpclient._HTTPConnection):
 
 def WebSocketConnect(url, io_loop=None, callback=None):
     if io_loop is None:
-        io_loop = IOLoop.instance()
+        io_loop = IOLoop.current()
     request = simple_httpclient.HTTPRequest(url)
     request = simple_httpclient._RequestProxy(
         request, simple_httpclient.HTTPRequest._DEFAULTS)