gh-157870: Do not count Rosetta's thread when warning about fork() with threads - #158553
Closed
Mohamed-Elshesheny wants to merge 1 commit into
Closed
Mohamed-Elshesheny wants to merge 1 commit into
Mohamed-Elshesheny wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 throughtask_threads(), soos.fork()andos.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:
test_fork_does_not_warn_when_single_threadedfails on main with the warning and passes with the change.test_fork_warns_when_non_python_thread_existsstill passes, so a real second thread still warns.test_os test_pty test_threading test_fork1 test_subprocesspass 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.