From a706b98bd8842b190c6a3e16e28186adb6d131a1 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Wed, 8 Feb 2023 20:12:47 +0000 Subject: [PATCH 1/3] asyncio: Remove obsolete code AsyncioLoop.start() used to save, set, and restore the thread-local event loop. This avoided some edge cases in early versions of asyncio; this appears to no longer be necessary since Python 3.7 introduced the get_running_loop() method. Removing this logic improves compatibility with Python 3.12, where it is difficult if not impossible to do the same thing without generating DeprecationWarnings. --- tornado/platform/asyncio.py | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index d839e87d6a..a3fbdc37e3 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -74,19 +74,6 @@ def _atexit_callback() -> None: atexit.register(_atexit_callback) -if sys.version_info >= (3, 10): - - def _get_event_loop() -> asyncio.AbstractEventLoop: - try: - return asyncio.get_running_loop() - except RuntimeError: - pass - - return asyncio.get_event_loop_policy().get_event_loop() - -else: - from asyncio import get_event_loop as _get_event_loop - class BaseAsyncIOLoop(IOLoop): def initialize( # type: ignore @@ -205,15 +192,7 @@ def _handle_events(self, fd: int, events: int) -> None: handler_func(fileobj, events) def start(self) -> None: - try: - old_loop = _get_event_loop() - except (RuntimeError, AssertionError): - old_loop = None # type: ignore - try: - asyncio.set_event_loop(self.asyncio_loop) - self.asyncio_loop.run_forever() - finally: - asyncio.set_event_loop(old_loop) + self.asyncio_loop.run_forever() def stop(self) -> None: self.asyncio_loop.stop() From 6a2c60c62a95248458c5d6206538b63c6e259cc7 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Wed, 8 Feb 2023 17:47:27 +0000 Subject: [PATCH 2/3] ci: Re-enable Python 3.12 alphas As of 3.12a5 the deprecation warnings should be in their final state. Also update setup-python action to silence a warning. --- .github/workflows/build.yml | 4 ++-- .github/workflows/test.yml | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f56564249..8734328f4f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 name: Install Python with: python-version: ${{ env.python-version }} @@ -47,7 +47,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 name: Install Python with: python-version: ${{ env.python-version }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 21fd213d1b..997ed1183a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 name: Install Python with: # Lint python version must be synced with tox.ini @@ -44,10 +44,8 @@ jobs: tox_env: py310-full - python: '3.11' tox_env: py311-full - # Need more work for python 3.12. See - # https://github.com/python/cpython/issues/93453 - #- python: '3.12.0-alpha - 3.12' - # tox_env: py312-full + - python: '3.12.0-alpha - 3.12' + tox_env: py312-full - python: 'pypy-3.8' # Pypy is a lot slower due to jit warmup costs, so don't run the # "full" test config there. @@ -58,7 +56,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 name: Install Python with: python-version: ${{ matrix.python}} From 129e622215faffae534c60b7859e2ce8e66e7f01 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Wed, 8 Feb 2023 21:28:02 +0000 Subject: [PATCH 3/3] ci: Add Python 3.10.8 and 3.11.0 to the build matrix Early releases in these two branches had different deprecation warnings so we want to test them too. --- .github/workflows/test.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 997ed1183a..d9a6082dd0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,8 +42,15 @@ jobs: tox_env: py39-full - python: '3.10' tox_env: py310-full + - python: '3.10.8' + # Early versions of 3.10 and 3.11 had different deprecation + # warnings in asyncio. Test with them too to make sure everything + # works the same way. + tox_env: py310-full - python: '3.11' tox_env: py311-full + - python: '3.11.0' + tox_env: py311-full - python: '3.12.0-alpha - 3.12' tox_env: py312-full - python: 'pypy-3.8'