From aea4c2094b4dafcf1a81f9792f44663e90f1b8b7 Mon Sep 17 00:00:00 2001 From: Joongi Kim Date: Sat, 9 Dec 2023 21:24:20 +0900 Subject: [PATCH] Add Python 3.12 support (#64) * ci: Include Python 3.12 as one of primary test targets * doc: Mention the child watcher API deprecation issue * ci: Upgrade black (23.7.0 -> 23.9.1) * setup: Update the trove classifier to include Python 3.12 --- .github/workflows/default.yml | 5 +---- .gitignore | 1 + changes/64.feature.md | 1 + setup.cfg | 5 +++-- src/aiotools/server.py | 26 ++++++++++++++------------ 5 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 changes/64.feature.md diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index 16c9641..f9c7f93 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -12,10 +12,7 @@ jobs: os: [ubuntu-latest, macos-latest] python-version: - "3.11" - experimental: [false] - include: - - python-version: "~3.12.0-0" - experimental: true + - "3.12" steps: - uses: actions/checkout@v3 - name: Set up Python diff --git a/.gitignore b/.gitignore index acdcd18..1605abb 100644 --- a/.gitignore +++ b/.gitignore @@ -82,6 +82,7 @@ celerybeat-schedule .envrc # virtualenv +.venv/ venv/ ENV/ diff --git a/changes/64.feature.md b/changes/64.feature.md new file mode 100644 index 0000000..3071e57 --- /dev/null +++ b/changes/64.feature.md @@ -0,0 +1 @@ +Add Python 3.12 support diff --git a/setup.cfg b/setup.cfg index 5e2ad2c..7fcb211 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,6 +15,7 @@ classifiers = Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Topic :: Software Development url = https://github.com/achimnol/aiotools project_urls = @@ -41,7 +42,7 @@ build = twine~=4.0 towncrier~=22.12 test = - pytest~=7.2.2 + pytest~=7.4.2 pytest-asyncio~=0.21 pytest-cov pytest-mock @@ -53,7 +54,7 @@ lint = ruff>=0.0.285 ruff-lsp>=0.0.37 typecheck = - mypy~=1.4.1 + mypy~=1.5.1 docs = sphinx~=4.3 sphinx-rtd-theme~=1.0 diff --git a/src/aiotools/server.py b/src/aiotools/server.py index 6dbc618..a570809 100644 --- a/src/aiotools/server.py +++ b/src/aiotools/server.py @@ -228,18 +228,20 @@ def helper(*args, **kwargs): def setup_child_watcher(loop: asyncio.AbstractEventLoop) -> None: - try: - watcher_cls = getattr(asyncio, "PidfdChildWatcher", None) - if _has_pidfd and watcher_cls: - watcher = watcher_cls() - asyncio.set_child_watcher(watcher) - else: - # Just get the default child watcher. - watcher = asyncio.get_child_watcher() - if not watcher.is_active(): - watcher.attach_loop(loop) - except NotImplementedError: - pass # for uvloop + if sys.version_info < (3, 12, 0): + # see python/cpython#94597 (issue) and python/cpython#98215 (pr) + try: + watcher_cls = getattr(asyncio, "PidfdChildWatcher", None) + if _has_pidfd and watcher_cls: + watcher = watcher_cls() + asyncio.set_child_watcher(watcher) + else: + # Just get the default child watcher. + watcher = asyncio.get_child_watcher() + if not watcher.is_active(): + watcher.attach_loop(loop) + except NotImplementedError: + pass # for uvloop async def cancel_all_tasks() -> None: