Skip to content

Commit

Permalink
Set multiprocessing start method to fork
Browse files Browse the repository at this point in the history
Since the current code requires forking, set it explicitly rather than disabling
parallelization on macOS.
  • Loading branch information
samdoran committed Oct 28, 2021
1 parent 4c91c03 commit 8322576
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
7 changes: 0 additions & 7 deletions sphinx/application.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 8322576

Please sign in to comment.