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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions sphinx/application.py
Expand Up @@ -12,7 +12,6 @@

import os
import pickle
import platform
import sys
import warnings
from collections import deque
Expand Down Expand Up @@ -195,12 +194,6 @@ def __init__(self, srcdir: str, confdir: Optional[str], outdir: str, doctreedir:
# say hello to the world
logger.info(bold(__('Running Sphinx v%s') % sphinx.__display_version__))

# notice for parallel build on macOS and py38+
if sys.version_info > (3, 8) and platform.system() == 'Darwin' and parallel > 1:
logger.info(bold(__("For security reasons, parallel mode is disabled on macOS and "
"python3.8 and above. For more details, please read "
"https://github.com/sphinx-doc/sphinx/issues/6803")))

# status code for command-line application
self.statuscode = 0

Expand Down
15 changes: 4 additions & 11 deletions sphinx/util/parallel.py
Expand Up @@ -9,8 +9,6 @@
"""

import os
import platform
import sys
import time
import traceback
from math import sqrt
Expand All @@ -28,12 +26,7 @@


# our parallel functionality only works for the forking Process
#
# Note: "fork" is not recommended on macOS and py38+.
# see https://bugs.python.org/issue33725
parallel_available = (multiprocessing and
(os.name == 'posix') and
not (sys.version_info > (3, 8) and platform.system() == 'Darwin'))
parallel_available = multiprocessing and os.name == 'posix'


class SerialTasks:
Expand Down Expand Up @@ -64,7 +57,7 @@ def __init__(self, nproc: int) -> None:
# task arguments
self._args: Dict[int, Optional[List[Any]]] = {}
# list of subprocesses (both started and waiting)
self._procs: Dict[int, multiprocessing.Process] = {}
self._procs: Dict[int, multiprocessing.context.ForkProcess] = {}
# list of receiving pipe connections of running subprocesses
self._precvs: Dict[int, Any] = {}
# list of receiving pipe connections of waiting subprocesses
Expand Down Expand Up @@ -96,8 +89,8 @@ def add_task(self, task_func: Callable, arg: Any = None, result_func: Callable =
self._result_funcs[tid] = result_func or (lambda arg, result: None)
self._args[tid] = arg
precv, psend = multiprocessing.Pipe(False)
proc = multiprocessing.Process(target=self._process,
args=(psend, task_func, arg))
context = multiprocessing.get_context('fork')
proc = context.Process(target=self._process, args=(psend, task_func, arg))
self._procs[tid] = proc
self._precvsWaiting[tid] = precv
self._join_one()
Expand Down
4 changes: 0 additions & 4 deletions tests/test_util_logging.py
Expand Up @@ -10,8 +10,6 @@

import codecs
import os
import platform
import sys

import pytest
from docutils import nodes
Expand Down Expand Up @@ -311,8 +309,6 @@ def test_colored_logs(app, status, warning):


@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
@pytest.mark.xfail(platform.system() == 'Darwin' and sys.version_info > (3, 8),
reason="Not working on macOS and py38")
def test_logging_in_ParallelTasks(app, status, warning):
logging.setup(app, status, warning)
logger = logging.getLogger(__name__)
Expand Down