Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set multiprocessing start method to fork #9793

Merged
merged 1 commit into from Dec 11, 2021

Conversation

samdoran
Copy link
Contributor

@samdoran samdoran commented Oct 28, 2021

Subject: Set multiprocessing start method to fork

Feature or Bugfix

  • Bugfix

Purpose

Explicitly set the multiprocessing start method to fork since the code depends on this behavior.

Detail

Since Python 3.8, the default start method was changed to spawn on macOS, which is incompatible with how Sphinx handles parallelization. The change was made in macOS not due to a new security concern but because Apple decided to prevent potential problems with calling something between fork() and exec() by failing early. This problem is not unique to macOS or even Python, and depends on the implementation.

From looking at the use of multiprocessing in Sphinx, I don't believe this will cause issues on macOS.

Relates

Since the current code requires forking, set it explicitly rather than disabling
parallelization on macOS.
@tk0miya tk0miya added api:cmdline type:proposal a feature suggestion labels Nov 11, 2021
@tk0miya tk0miya added this to the 4.4.0 milestone Nov 11, 2021
@tk0miya
Copy link
Member

tk0miya commented Nov 11, 2021

Thank you for the proposal. It would be exciting if we can support a parallel build on macOS again!

From looking at the use of multiprocessing in Sphinx, I don't believe this will cause issues on macOS.

Before merging this, could you let us know why do you think so? I'm not expert of the internal Python and macOS. So I can't determine why Sphinx will not cause issues.

@samdoran
Copy link
Contributor Author

Before merging this, could you let us know why do you think so? I'm not expert of the internal Python and macOS. So I can't determine why Sphinx will not cause issues.

The problem is that calling into the Objective-C runtime between fork() and exec() is unsafe. This has always been the case. Apple chose to make calls like this fail early and deterministically rather than (potentially) failing later and in unpredictable ways.

From looking at the system calls using dtruss that Sphinx makes as well as testing parallel builds on macOS, Sphinx does not run into this, explicitly or implicitly.

@tk0miya
Copy link
Member

tk0miya commented Dec 11, 2021

Thank you for your detailed explanation. I read https://bugs.python.org/issue33725 again and understand the problem (maybe). Indeed, Sphinx does not do anything between fork and exec. Okay, let's see what happens with this.

@tk0miya tk0miya merged commit 4c7df3f into sphinx-doc:4.x Dec 11, 2021
tk0miya added a commit that referenced this pull request Dec 11, 2021
@samdoran samdoran deleted the enable-parallel-on-macos branch December 13, 2021 15:02
@samdoran
Copy link
Contributor Author

Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api:cmdline type:proposal a feature suggestion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants