From: Thomas Kluyver Date: Wed, 15 Feb 2023 14:36:19 +0000 (+0000) Subject: Deprecate IOLoop(make_current=True) X-Git-Tag: v6.3.0b1~8^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f40296bc3858d1d06358fe3c65bc6e850347685;p=thirdparty%2Ftornado.git Deprecate IOLoop(make_current=True) --- diff --git a/tornado/ioloop.py b/tornado/ioloop.py index ce21ad44b..d698a97e1 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -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: diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index 557ebc375..a0ce493a9 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -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.