Skip to content

Commit

Permalink
Run write_doc_serialized after resolve in subproc
Browse files Browse the repository at this point in the history
  • Loading branch information
ubmarco committed Nov 1, 2023
1 parent 73938c0 commit 702de5b
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions sphinx/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,15 @@ def _write_serial(self, docnames: Sequence[str]) -> None:
self.write_doc(docname, doctree)

def _write_parallel(self, docnames: Sequence[str], nproc: int) -> None:
# warm up caches/compile templates using the first document
with TimeIt(f'{__file__}: {inspect.currentframe().f_code.co_name}: write 1st doc', self.runtime, logger):

Check failure on line 611 in sphinx/builders/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sphinx/builders/__init__.py:611:96: E501 Line too long (113 > 95 characters)
firstname, docnames = docnames[0], docnames[1:]
self.app.phase = BuildPhase.RESOLVING
doctree = self.env.get_and_resolve_doctree(firstname, self)
self.app.phase = BuildPhase.WRITING
self.write_doc_serialized(firstname, doctree)
self.write_doc(firstname, doctree)

def write_process(worker_id: int, docname: str) -> tuple[list[str], dict[str, str]]:
# print(f'{getpid()}: {docname}')
# print(f'{worker_id}: {docname}')
Expand All @@ -615,7 +624,7 @@ def write_process(worker_id: int, docname: str) -> tuple[list[str], dict[str, st

self.app.phase = BuildPhase.WRITING
doctree = self.env.get_and_resolve_doctree(docname, self)
# self.write_doc_serialized(docname, doctree)
self.write_doc_serialized(docname, doctree)
self.write_doc(docname, doctree)
# get warnings to log them in the main process, removing empty values
# (in case the last ends on \n)
Expand All @@ -630,15 +639,6 @@ def write_process(worker_id: int, docname: str) -> tuple[list[str], dict[str, st
# new_warnings.append(warn_clean)
return self.app._warnings_parallel, self.images

# warm up caches/compile templates using the first document
with TimeIt(f'{__file__}: {inspect.currentframe().f_code.co_name}: write 1st doc', self.runtime, logger):
firstname, docnames = docnames[0], docnames[1:]
self.app.phase = BuildPhase.RESOLVING
doctree = self.env.get_and_resolve_doctree(firstname, self)
self.app.phase = BuildPhase.WRITING
self.write_doc_serialized(firstname, doctree)
self.write_doc(firstname, doctree)

# tasks = ParallelTasks(nproc)
# chunks = make_chunks(docnames, nproc)

Expand All @@ -652,15 +652,15 @@ def on_chunk_done(args: list[tuple[str, NoneType]], result: NoneType) -> None:

self.app.phase = BuildPhase.RESOLVING
if docnames:
measure_1 = f'{__file__}: {inspect.currentframe().f_code.co_name}: get_doctree_write'
measure_2 = f'{__file__}: {inspect.currentframe().f_code.co_name}: write_doc_serialized'
for docname in docnames:
with TimeIt(measure_1, self.runtime, logger, False):
doctree = self.env.get_doctree_write(docname)
with TimeIt(measure_2, self.runtime, logger, False):
self.write_doc_serialized(docname, doctree)
logger.info(f'{measure_1}: {self.runtime[measure_1]}')
logger.info(f'{measure_2}: {self.runtime[measure_2]}')
# measure_1 = f'{__file__}: {inspect.currentframe().f_code.co_name}: get_doctree_write'

Check failure on line 655 in sphinx/builders/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sphinx/builders/__init__.py:655:96: E501 Line too long (99 > 95 characters)
# measure_2 = f'{__file__}: {inspect.currentframe().f_code.co_name}: write_doc_serialized'

Check failure on line 656 in sphinx/builders/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sphinx/builders/__init__.py:656:96: E501 Line too long (102 > 95 characters)
# for docname in docnames:
# with TimeIt(measure_1, self.runtime, logger, False):
# doctree = self.env.get_doctree_write(docname)
# with TimeIt(measure_2, self.runtime, logger, False):
# self.write_doc_serialized(docname, doctree)
# logger.info(f'{measure_1}: {self.runtime[measure_1]}')
# logger.info(f'{measure_2}: {self.runtime[measure_2]}')

with WorkerPool(n_jobs=nproc, start_method='fork', use_dill=False, pass_worker_id=True, enable_insights=True) as pool:

Check failure on line 665 in sphinx/builders/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sphinx/builders/__init__.py:665:96: E501 Line too long (130 > 95 characters)
# args = []
Expand Down

0 comments on commit 702de5b

Please sign in to comment.