sphinx-doc / sphinx-doc/sphinx

Use "spawn" instead of "fork" multiprocessing

Open
#12,201 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

internals:parallel type:bug
Dominant language
Python
Stars
8k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

Parallel build hangs with some libraries as multiprocessing "fork" start method is unreliable and breaks multithreading:
https://docs.pola.rs/user-guide/misc/multiprocessing/
https://github.com/pola-rs/polars/issues/7535
This becomes an issue when custom sphinx hooks using such libraries are used.

Fundamentally, the "fork" method is somewhat broken as cannot generally be expected to work. I'm not sure what is the best way to handle that considered "spawn" is a lot slower (requires re-importing modules), but maybe it's ok with a long-lived pool.

How to Reproduce

I haven't managed to drill down a minimal reproducer unfortunately. The issue happens when calling polars.LazyFrame.collect() in our case, as this will trigger multithreaded work in an extension module (Rust code of polars, probably does not hold the GIL for all the computations but allows Python callbacks so it must to some extent, sometimes).

Environment Information
Platform:              linux; (Linux-5.15.0-92-generic-x86_64-with-glibc2.31)
Python version:        3.11.7 (main, Dec  8 2023, 18:56:57) [GCC 9.4.0])
Python implementation: CPython
Sphinx version:        7.2.6
Docutils version:      0.20.1
Jinja2 version:        3.1.3
Pygments version:      2.17.2
Sphinx extensions

No response

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the parallel build with a custom Sphinx hook that calls polars.LazyFrame.collect(), then trace the multiprocessing entry point and its fork/spawn handling. Done means the affected build no longer hangs with multithreaded extension work and existing parallel-build behavior remains covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.