From 83225767cbe41294b97c63e34efe455fd2a9338d Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Thu, 28 Oct 2021 12:38:56 -0400 Subject: [PATCH] Set multiprocessing start method to fork Since the current code requires forking, set it explicitly rather than disabling parallelization on macOS. --- sphinx/application.py | 7 ------- sphinx/util/parallel.py | 15 ++++----------- tests/test_util_logging.py | 4 ---- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/sphinx/application.py b/sphinx/application.py index 4a75a83fec3..d02f11faca1 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -12,7 +12,6 @@ import os import pickle -import platform import sys import warnings from collections import deque @@ -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 diff --git a/sphinx/util/parallel.py b/sphinx/util/parallel.py index 2a83d6297f8..d7abc81df63 100644 --- a/sphinx/util/parallel.py +++ b/sphinx/util/parallel.py @@ -9,8 +9,6 @@ """ import os -import platform -import sys import time import traceback from math import sqrt @@ -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: @@ -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 @@ -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() diff --git a/tests/test_util_logging.py b/tests/test_util_logging.py index a03f62b0122..7b0369150eb 100644 --- a/tests/test_util_logging.py +++ b/tests/test_util_logging.py @@ -10,8 +10,6 @@ import codecs import os -import platform -import sys import pytest from docutils import nodes @@ -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__)