]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Deprecate IOLoop(make_current=True)
authorThomas Kluyver <thomas@kluyver.me.uk>
Wed, 15 Feb 2023 14:36:19 +0000 (14:36 +0000)
committerThomas Kluyver <thomas@kluyver.me.uk>
Wed, 15 Feb 2023 14:36:19 +0000 (14:36 +0000)
tornado/ioloop.py
tornado/test/ioloop_test.py

index ce21ad44bd5a2b016eeb9f7680865bacba4bc93e..d698a97e10301363f30db57379b9e2696de60008 100644 (file)
@@ -143,6 +143,11 @@ class IOLoop(Configurable):
        Uses the `asyncio` event loop by default. The ``IOLoop.configure`` method
        cannot be used on Python 3 except to redundantly specify the `asyncio`
        event loop.
+
+    .. versionchanged:: 6.3
+       ``make_current=False`` is now the default when creating an IOLoop -
+       previously the default was to make the event loop current if there wasn't
+       already a current one. Passing ``make_current=True`` is deprecated.
     """
 
     # These constants were originally based on constants from the epoll module.
@@ -268,7 +273,7 @@ class IOLoop(Configurable):
             if instance:
                 from tornado.platform.asyncio import AsyncIOMainLoop
 
-                current = AsyncIOMainLoop(make_current=True)  # type: Optional[IOLoop]
+                current = AsyncIOMainLoop()  # type: Optional[IOLoop]
             else:
                 current = None
         return current
@@ -336,11 +341,13 @@ class IOLoop(Configurable):
 
         return AsyncIOLoop
 
-    def initialize(self, make_current: Optional[bool] = None) -> None:
-        if make_current is None:
-            if IOLoop.current(instance=False) is None:
-                self.make_current()
-        elif make_current:
+    def initialize(self, make_current: bool = False) -> None:
+        if make_current:
+            warnings.warn(
+                "IOLoop(make_current=True) is deprecated",
+                DeprecationWarning,
+                stacklevel=2,
+            )
             current = IOLoop.current(instance=False)
             # AsyncIO loops can already be current by this point.
             if current is not None and current is not self:
index 557ebc3757ec3f4dcf65cff7c957ae38f3aeddf1..a0ce493a9ab96c480cfd8bbe1445d08f44e0842f 100644 (file)
@@ -450,15 +450,6 @@ class TestIOLoopCurrent(unittest.TestCase):
         if self.io_loop is not None:
             self.io_loop.close()
 
-    def test_default_current(self):
-        self.io_loop = IOLoop()
-        # The first IOLoop with default arguments is made current.
-        self.assertIs(self.io_loop, IOLoop.current())
-        # A second IOLoop can be created but is not made current.
-        io_loop2 = IOLoop()
-        self.assertIs(self.io_loop, IOLoop.current())
-        io_loop2.close()
-
     def test_non_current(self):
         self.io_loop = IOLoop(make_current=False)
         # The new IOLoop is not initially made current.