Skip to content

Conversation

cxzhong
Copy link
Contributor

@cxzhong cxzhong commented Oct 10, 2025

Python 3.14 changed the default multiprocessing start method from fork to forkserver on Linux. This caused pickling errors in the doctest framework because DocTestWorker objects contained unpicklable local functions.

The fix ensures that the fork start method is always used on all platforms, not just macOS, since Sage's doctesting framework requires the 'fork' method to function correctly.

Changes:

  • src/sage/doctest/forker.py: Remove Darwin-only check, always use fork
  • src/sage/doctest/external.py: Remove Darwin-only check, always use fork

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

Python 3.14 changed the default multiprocessing start method from 'fork'
to 'forkserver' on Linux. This caused pickling errors in the doctest
framework because DocTestWorker objects contained unpicklable local
functions.

The fix ensures that the 'fork' start method is always used on all
platforms, not just macOS, since Sage's doctesting framework requires
the 'fork' method to function correctly.

Changes:
- src/sage/doctest/forker.py: Remove Darwin-only check, always use fork
- src/sage/doctest/external.py: Remove Darwin-only check, always use fork
@cxzhong cxzhong marked this pull request as ready for review October 10, 2025 03:35
@Copilot Copilot AI review requested due to automatic review settings October 10, 2025 03:35
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes multiprocessing compatibility issues with Python 3.14 by ensuring Sage's doctest framework always uses the 'fork' start method. Python 3.14 changed the default multiprocessing start method from 'fork' to 'forkserver' on Linux, which causes pickling errors in Sage's doctesting framework since DocTestWorker objects contain unpicklable local functions.

  • Removes platform-specific (Darwin-only) checks for setting the multiprocessing start method
  • Updates comments to explain the Python 3.14 compatibility requirement
  • Ensures 'fork' method is used consistently across all platforms

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/sage/doctest/forker.py Removes Darwin-only check and always sets 'fork' method with updated comment
src/sage/doctest/external.py Removes Darwin-only check and always sets 'fork' method with updated comment

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

Documentation preview for this PR (built with commit b30e0b0; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@cxzhong
Copy link
Contributor Author

cxzhong commented Oct 10, 2025

@dimpase I think we should move on this. without this, the doctest goes wrong in python 3.14.

@dimpase
Copy link
Member

dimpase commented Oct 10, 2025

OK

@dimpase
Copy link
Member

dimpase commented Oct 10, 2025

this should be conditional on the Python version. What's OK for 3.14 is not good for <3.14

@cxzhong
Copy link
Contributor Author

cxzhong commented Oct 10, 2025

this should be conditional on the Python version. What's OK for 3.14 is not good for <3.14

But seems all CI pass under python 3.13 and older versions. and before python 3.14, the default start method of multiprocess is fork on linux and spawn on MacOS. But in python 3.14+, It has changed to forkserver on linux. you can refer to https://docs.python.org/it/3.14/whatsnew/3.14.html

On Unix platforms other than macOS, “forkserver” is now the the default start method for ProcessPoolExecutor (replacing “fork”). This change does not affect Windows or macOS, where “spawn” remains the default start method.

If the threading incompatible fork method is required, you must explicitly request it by supplying a multiprocessing context mp_context to ProcessPoolExecutor.

See forkserver restrictions for information and differences with the fork method and how this change may affect existing code with mutable global shared variables and/or shared objects that can not be automatically pickled.

Besides, our forker.py and externel.py must rely on fork.

@dimpase
Copy link
Member

dimpase commented Oct 10, 2025

Right, I misread your patch. apologies. All good.

vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 11, 2025
sagemathgh-41023: Fix multiprocessing start method for Python 3.14 compatibility
    
Python 3.14 changed the default multiprocessing start method from
``fork`` to ``forkserver`` on Linux. This caused pickling errors in the
doctest framework because DocTestWorker objects contained unpicklable
local functions.

The fix ensures that the ``fork`` start method is always used on all
platforms, not just macOS, since Sage's doctesting framework requires
the 'fork' method to function correctly.

Changes:
- src/sage/doctest/forker.py: Remove Darwin-only check, always use fork
- src/sage/doctest/external.py: Remove Darwin-only check, always use
fork

<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#41023
Reported by: Chenxin Zhong
Reviewer(s): Copilot, Dima Pasechnik
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 12, 2025
sagemathgh-41023: Fix multiprocessing start method for Python 3.14 compatibility
    
Python 3.14 changed the default multiprocessing start method from
``fork`` to ``forkserver`` on Linux. This caused pickling errors in the
doctest framework because DocTestWorker objects contained unpicklable
local functions.

The fix ensures that the ``fork`` start method is always used on all
platforms, not just macOS, since Sage's doctesting framework requires
the 'fork' method to function correctly.

Changes:
- src/sage/doctest/forker.py: Remove Darwin-only check, always use fork
- src/sage/doctest/external.py: Remove Darwin-only check, always use
fork

<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#41023
Reported by: Chenxin Zhong
Reviewer(s): Copilot, Dima Pasechnik
@vbraun vbraun merged commit 057ae85 into sagemath:develop Oct 16, 2025
26 checks passed
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.

3 participants