]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Default make_current -> True, remove check for existing event loop
authorThomas Kluyver <thomas@kluyver.me.uk>
Thu, 16 Feb 2023 12:59:02 +0000 (12:59 +0000)
committerThomas Kluyver <thomas@kluyver.me.uk>
Thu, 16 Feb 2023 12:59:02 +0000 (12:59 +0000)
tornado/ioloop.py
tornado/platform/asyncio.py
tornado/test/ioloop_test.py

index d698a97e10301363f30db57379b9e2696de60008..bea2ca0b2c710fe30864cae1164ce85ecc293f46 100644 (file)
@@ -145,9 +145,9 @@ class IOLoop(Configurable):
        event loop.
 
     .. versionchanged:: 6.3
-       ``make_current=False`` is now the default when creating an IOLoop -
+       ``make_current=True`` 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.
+       already a current one.
     """
 
     # These constants were originally based on constants from the epoll module.
@@ -298,6 +298,14 @@ class IOLoop(Configurable):
            Setting and clearing the current event loop through Tornado is
            deprecated. Use ``asyncio.set_event_loop`` instead if you need this.
         """
+        warnings.warn(
+            "make_current is deprecated; start the event loop first",
+            DeprecationWarning,
+            stacklevel=2,
+        )
+        self._make_current()
+
+    def _make_current(self):
         # The asyncio event loops override this method.
         raise NotImplementedError()
 
@@ -341,18 +349,9 @@ class IOLoop(Configurable):
 
         return AsyncIOLoop
 
-    def initialize(self, make_current: bool = False) -> None:
+    def initialize(self, make_current: bool = True) -> 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:
-                raise RuntimeError("current IOLoop already exists")
-            self.make_current()
+            self._make_current()
 
     def close(self, all_fds: bool = False) -> None:
         """Closes the `IOLoop`, freeing any resources used.
index a3fbdc37e39deaf63c86dda11fe13f2f5aca33a8..a9fa890047b704ed102061440c1a9d14fb4d7d9a 100644 (file)
@@ -276,7 +276,7 @@ class AsyncIOMainLoop(BaseAsyncIOLoop):
     def initialize(self, **kwargs: Any) -> None:  # type: ignore
         super().initialize(asyncio.get_event_loop(), **kwargs)
 
-    def make_current(self) -> None:
+    def _make_current(self) -> None:
         # AsyncIOMainLoop already refers to the current asyncio loop so
         # nothing to do here.
         pass
@@ -327,12 +327,7 @@ class AsyncIOLoop(BaseAsyncIOLoop):
             self._clear_current()
         super().close(all_fds=all_fds)
 
-    def make_current(self) -> None:
-        warnings.warn(
-            "make_current is deprecated; start the event loop first",
-            DeprecationWarning,
-            stacklevel=2,
-        )
+    def _make_current(self):
         if not self.is_current:
             try:
                 self.old_asyncio = asyncio.get_event_loop()
index a0ce493a9ab96c480cfd8bbe1445d08f44e0842f..7de392f83e6c70bfdc8875d340c75e90b21668ce 100644 (file)
@@ -472,11 +472,6 @@ class TestIOLoopCurrent(unittest.TestCase):
     def test_force_current(self):
         self.io_loop = IOLoop(make_current=True)
         self.assertIs(self.io_loop, IOLoop.current())
-        with self.assertRaises(RuntimeError):
-            # A second make_current=True construction cannot succeed.
-            IOLoop(make_current=True)
-        # current() was not affected by the failed construction.
-        self.assertIs(self.io_loop, IOLoop.current())
 
 
 class TestIOLoopCurrentAsync(AsyncTestCase):