Skip to content

gh-157870: Do not count Rosetta's thread when warning about fork() with threads - #158553

Closed
Mohamed-Elshesheny wants to merge 1 commit into
python:mainfrom
Mohamed-Elshesheny:gh-157870-rosetta-fork-warning
Closed

Mohamed-Elshesheny wants to merge 1 commit into
python:mainfrom
Mohamed-Elshesheny:gh-157870-rosetta-fork-warning

Conversation

@Mohamed-Elshesheny

@Mohamed-Elshesheny Mohamed-Elshesheny commented Oct 1, 2026 •

Copy link
Copy Markdown

On Apple Silicon, Rosetta 2 runs a thread of its own, named com.apple.rosetta.exceptionserver, in every translated x86-64 process. get_number_of_os_threads() counts it through task_threads(), so os.fork() and os.forkpty() warn that a single-threaded process is multi-threaded.

This skips that thread by name, as suggested in #157870 (comment). The check is compiled only into x86-64 builds, since Rosetta translates nothing else.

Tested on an Apple Silicon Mac (M1 Max, macOS 27.0.1) with builds of this branch for both architectures:

  • x86-64 under Rosetta: the new test test_fork_does_not_warn_when_single_threaded fails on main with the warning and passes with the change. test_fork_warns_when_non_python_thread_exists still passes, so a real second thread still warns.
  • arm64: both tests pass. The new code is compiled out there.
  • test_os test_pty test_threading test_fork1 test_subprocess pass on both builds (1,185 tests run on each).

The new test is not specific to Rosetta. It asserts that a single-threaded process forks without the warning, which is what fails under Rosetta today. A small C program listing the task's threads shows the extra one on this Mac: one unnamed thread when built for arm64, two when built for x86-64, the second named com.apple.rosetta.exceptionserver.

One thing I did not change: this function never releases what task_threads() returns (the thread ports and the array). That is the same before and after, and I kept it out to keep this to the issue.

…k() with threads

On Apple Silicon, Rosetta 2 runs a thread of its own in every translated
x86-64 process. get_number_of_os_threads() counted it, so os.fork() and
os.forkpty() warned that a single-threaded process was multi-threaded.
@python-cla-bot

python-cla-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant