File: recipes-multiprocessing.rst

package info (click to toggle)
pymupdf 1.25.4%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 98,632 kB
  • sloc: python: 43,379; ansic: 75; makefile: 6
file content (45 lines) | stat: -rw-r--r-- 1,075 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
.. include:: header.rst

.. _RecipesMultiprocessing:


.. |toggleStart| raw:: html

   <details>
   <summary><a>See code</a></summary>

.. |toggleEnd| raw:: html

   </details>

==============================
Multiprocessing
==============================

|PyMuPDF| does not support running on multiple threads - doing so may cause incorrect behaviour or even crash Python itself.

However, there is the option to use :title:`Python's` *multiprocessing* module in a variety of ways.

If you are looking to speed up page-oriented processing for a large document, use this script as a starting point. It should be at least twice as fast as the corresponding sequential processing.


|toggleStart|

.. literalinclude:: samples/multiprocess-render.py
   :language: python

|toggleEnd|


Here is a more complex example involving inter-process communication between a main process (showing a GUI) and a child process doing |PyMuPDF| access to a document.


|toggleStart|

.. literalinclude:: samples/multiprocess-gui.py
   :language: python

|toggleEnd|


.. include:: footer.rst