Clarification on thread safety #4778
Answered
by
JorjMcKie
vikigenius
asked this question in
Q&A
|
The docs say I am running in async context async def handle_request(path: str):
await asyncio.to_thread(extract_pdf(path))def extract_pdf(path: str):
with pymupdf.open(path) as pdf:
do_extract()Is this pattern inherently unsafe because of the asyncio.to_thread? Even though no pymupdf objects are shared across thread boundaries? |
Answered by
JorjMcKie
Nov 6, 2025
Replies: 2 comments 2 replies
|
This is no issue, but either a Discussions item or even better should be discussed on our Forum. |
0 replies
|
We can not guarantee correct working in a threaded environment. The critical detail is the cache memory internally maintained by our base library MuPDF. |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you absolutely need parallel processing you should fallback to the multiprocessing module. Every process would have its own copy of MuPDF cache.