Closed kangtsang closed 8 months ago
This is expected: pdfium, and therefore also pypdfium2, are not thread-compatible: https://pypdfium2.readthedocs.io/en/stable/python_api.html#thread-incompatibility https://pdfium.googlesource.com/pdfium/+/b8ea87677cb882613f37094fe681876e9eaa3e16/public/fpdfview.h#11 It is not allowed to call pdfium functions simultaneously across different threads, not even with different documents.
However, you may still use pdfium in a threaded context if it is ensured that only a single pdfium call can be made at a time (e.g. do pdfium work only in one thread, and other work in other threads, or install a mutex to linearize pdfium calls throughout threads).
I decided not to wrap pdfium functions in a global mutex because it's not clear to me what impact that might have on performance (consider frequently-called APIs such as the FPDFText_GetChar*()
family, where there are already concerns with FFI overhead). Finer-grained locking as needed on the caller side seemed more elegant.
Checklist
pypdfium2
fromPyPI
orGitHub/pypdfium2-team
.Description
Reason for Generic issue (keyword/topic) using multiple threads to read pdf exception occurs
Description
Script to reproduce issue
Install Info
Validity