Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Comment on fork logic in docbuilding
Browse files Browse the repository at this point in the history
  • Loading branch information
saraedum committed Apr 21, 2018
1 parent 50898fe commit 95c6275
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/sage_setup/docbuild/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ def clean(self, *args):
inventory = builder_helper('inventory')

def build_many(target, args):
# Pool() uses an actual fork() to run each new instance. This is important
# for performance reasons, i.e., don't use a forkserver when it becomes
# available with Python 3: Here, sage is already initialized which is quite
# costly, with a forkserver we would have to reinitialize it for every
# document we build. At the same time, don't serialize this by taking the
# pool (and thus the call to fork()) out completely: The call to Sphinx
# leaks memory, so we need to build each document in its own process to
# control the RAM usage.
from multiprocessing import Pool
pool = Pool(NUM_THREADS, maxtasksperchild=1)
# map_async handles KeyboardInterrupt correctly. Plain map and
Expand Down
5 changes: 5 additions & 0 deletions src/sage_setup/docbuild/sphinxbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ def runsphinx():
try:
sys.stdout = SageSphinxLogger(sys.stdout, os.path.basename(output_dir))
sys.stderr = SageSphinxLogger(sys.stderr, os.path.basename(output_dir))
# Note that this call as of eraly 2018 leaks memory. So make sure that
# you don't call runsphinx() several times in a row. (i.e., you want to
# fork() somewhere before this call.)
# We don't use subprocess here, as we don't want to re-initialize Sage
# for every docbuild as this takes a while.
sphinx.cmdline.main(sys.argv)
sys.stderr.raise_errors()
sys.stdout.raise_errors()
Expand Down

0 comments on commit 95c6275

Please sign in to comment.