MCPcopy
hub / github.com/sphinx-doc/sphinx / _write_parallel

Method _write_parallel

sphinx/builders/__init__.py:779–818  ·  view source on GitHub ↗
(self, docnames: Sequence[str], nproc: int)

Source from the content-addressed store, hash-verified

777 _write_docname(docname, env=self.env, builder=self, tags=self.tags)
778
779 def _write_parallel(self, docnames: Sequence[str], nproc: int) -> None:
780 def write_process(docs: list[tuple[str, nodes.document]]) -> None:
781 self.phase = BuildPhase.WRITING
782 for docname, doctree in docs:
783 self.write_doc(docname, doctree)
784
785 # warm up caches/compile templates using the first document
786 firstname, docnames = docnames[0], docnames[1:]
787 _write_docname(firstname, env=self.env, builder=self, tags=self.tags)
788
789 tasks = ParallelTasks(nproc)
790 chunks = make_chunks(docnames, nproc)
791
792 # create a status_iterator to step progressbar after writing a document
793 # (see: ``on_chunk_done()`` function)
794 progress = status_iterator(
795 chunks,
796 __('writing output... '),
797 'darkgreen',
798 len(chunks),
799 self.config.verbosity,
800 )
801
802 def on_chunk_done(args: list[tuple[str, nodes.document]], result: None) -> None:
803 next(progress)
804
805 self.phase = BuildPhase.RESOLVING
806 for chunk in chunks:
807 arg = []
808 for docname in chunk:
809 doctree = self.env.get_and_resolve_doctree(
810 docname, self, tags=self.tags
811 )
812 self.write_doc_serialized(docname, doctree)
813 arg.append((docname, doctree))
814 tasks.add_task(write_process, arg, on_chunk_done)
815
816 # make sure all threads have finished
817 tasks.join()
818 logger.info('')
819
820 def prepare_writing(self, docnames: Set[str]) -> None:
821 """A place where you can add logic before :meth:`write_doc` is run"""

Callers 1

write_documentsMethod · 0.95

Calls 9

write_doc_serializedMethod · 0.95
add_taskMethod · 0.95
joinMethod · 0.95
ParallelTasksClass · 0.90
make_chunksFunction · 0.90
status_iteratorFunction · 0.90
_write_docnameFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected