Skip to content

Commit

Permalink
Never spawn more processes than we have pages
Browse files Browse the repository at this point in the history
This is particularly important for short PDFs on systems with high CPU
count.
Fixes
facebookresearch/nougat#96 (comment)
  • Loading branch information
mara004 committed Oct 17, 2023
1 parent 3be189f commit 3100bfe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/pypdfium2/_helpers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,11 @@ def render(
raise ValueError("Duplicate page indices are prohibited.")

converter_params = list( inspect.signature(converter).parameters )[1:]

pool_kwargs = dict(
initializer = _parallel_renderer_init,
initargs = (self._input, self._password, bool(self.formenv), mk_formconfig, renderer, converter, converter_params, pass_info, kwargs),
)
n_processes = min(n_processes, n_pages)
with mp.Pool(n_processes, **pool_kwargs) as pool:
yield from pool.imap(_parallel_renderer_job, page_indices)

Expand Down

0 comments on commit 3100bfe

Please sign in to comment.