Skip to content

Conversation

thearpankumar
Copy link

@thearpankumar thearpankumar commented Oct 6, 2025

❓ What kind of change does this PR introduce?

  • 🐞 bug fix
  • 🐣 feature
  • πŸ“‹ docs update
  • πŸ“‹ tests/coverage improvement
  • πŸ“‹ refactoring
  • πŸ’₯ other

πŸ“‹ What is the related issue number (starting with #)

Resolves #767

❓ What is the current behavior? (You can also link to an open issue here)

Python 3.14 tests fail in CI with:

  • Multiprocessing errors due to default start method change from fork to forkserver on Unix
  • IOBase cleanup errors during test teardown due to changed error message format
  • Pre-commit failures from flake8-annotations incompatibility

❓ What is the new behavior (if this is a feature change)?

All tests pass on Python 3.14 (Linux and Windows) with full backward compatibility for Python 3.8-3.13.

πŸ“‹ Other information:

Root Cause: Python 3.14 changed the default multiprocessing start method from fork to forkserver on Unix platforms, breaking pytest-xdist parallel test execution.

Solution Applied:

  1. Multiprocessing Fix (cheroot/test/conftest.py):

    • Force fork method on Python 3.14+ Unix systems only
    • Skip on Windows (doesn't support fork)
    • Clean exception handling with contextlib.suppress
  2. IOBase Warning Filter (pytest.ini):

    • Updated regex pattern to match Python 3.14's new error format
    • Changed from "Exception ignored in." to "Exception ignored.*"
  3. Pre-commit Config (.pre-commit-config.yaml):

    • Set flake8 language_version: python3.11 to match CI
    • Prevents flake8-annotations Python 3.14 incompatibility

Testing: Verified on Python 3.14.0rc3 with pytest-xdist parallel execution (n=auto).

πŸ“‹ Contribution checklist:

  • I wrote descriptive pull request text above
  • I think the code is well written
  • I wrote good commit messages
  • I have squashed related commits together after
    the changes have been approved
  • Unit tests for the changes exist
  • Integration tests for the changes exist (if applicable)
  • I used the same coding conventions as the rest of the project
  • The new code doesn't generate linter offenses
  • Documentation reflects the changes
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences

This change is Reviewable

thearpankumar and others added 8 commits October 4, 2025 10:08
Python 3.14 changed IOBase error message from 'Exception ignored in.'
to 'Exception ignored while calling deallocator', breaking the existing
regex filter. Updated to match both formats.

Also reverted .pre-commit-config.yaml to python3.14 (CI doesn't have 3.13).
… config

- Only force 'fork' on Unix (Windows doesn't support fork method)
- Change flake8 language_version to python3.11 for CI compatibility
- Fixes ValueError on Windows: 'cannot find context for fork'
- Replace try-except-pass with contextlib.suppress (ruff SIM105)
- Shorten comment lines to meet 79 char limit (flake8 LN002)
- Split nested try blocks to satisfy flake8 WPS229
- Remove unused WPS436 noqa comment
@webknjaz webknjaz changed the title (#767) Fix/python 314 compatiblity Fix Python 3.14 compatiblity Oct 6, 2025
- flake8-spellcheck ~= 0.28.0
- wemake-python-styleguide ~= 1.1.0
language_version: python3.11 # flake8-commas doesn't work w/ Python 3.12
# Use Python 3.11 for CI compatibility (flake8-annotations not 3.14 ready)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just update the existing comment. Disconnected comments tend to get lost. Also, it's obvious that Python 3.11 is used from YAML. No need to repeat things too verbosely for the sake of verboseness.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, only the old version is not compatible with Python 3.12. It's unknown if a newer isn't compatible with 3.14. But since there's a release with 3.13 in Trove classifiers, it would make sense to bump the dependency version and maybe bump this to 3.13 if that work + verify if 3.14 could work too.

Comment on lines +25 to +37
# Python 3.14 compatibility: Force 'fork' multiprocessing on Unix
# Python 3.14 changed default from 'fork' to 'forkserver' on Unix,
# which can cause issues with pytest-xdist's parallel test execution.
# This ensures compatibility with existing test fixtures and shared state.
# Note: Windows doesn't support 'fork', so we skip this on Windows.
# Ref: https://github.com/cherrypy/cheroot/issues/767
if sys.version_info >= (3, 14) and not IS_WINDOWS:
with contextlib.suppress(ImportError):
import multiprocessing

with contextlib.suppress(RuntimeError):
# Force fork method even if already set to forkserver
multiprocessing.set_start_method('fork', force=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem to have any proof of the justification. Show me fact-checking and actual research. Unnamed possible issues is too broad to make sense of it. Also, post the actual CI failure log (with a link to the line in the log) that this is supposedly addressing.

import pytest

from .._compat import IS_MACOS, IS_WINDOWS # noqa: WPS436
from .._compat import IS_MACOS, IS_WINDOWS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is unrelated and can be submitted separately.

Comment on lines +67 to +70
# Python 3.14: PEP 765 - control flow statements in finally blocks
# Added as defensive measure even though current code has no violations
# Ref: https://github.com/cherrypy/cheroot/issues/767
ignore::SyntaxWarning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must not be ignored. Definitely not as a blanket suppression without justification.

Comment on lines +63 to +65
# Python 3.14 changed error message format from "Exception ignored in." to
# "Exception ignored while calling deallocator", so we use a regex that matches both
ignore:Exception ignored.*IOBase.__del__:pytest.PytestUnraisableExceptionWarning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, this should be fixed. But since there was a suppression in place already, It's fine to keep it for now.

Comment on lines +72 to +75
# Python 3.14: Free-threaded build context-aware warnings
# Context-aware warnings may behave differently in free-threaded builds
# Ref: https://github.com/cherrypy/cheroot/issues/767
ignore:.*context.*:RuntimeWarning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't have any specifics and therefore is not a good/acceptable justification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python 3.14 compatibility

2 participants