Clarification on thread safety #4778
-
|
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? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
This is no issue, but either a Discussions item or even better should be discussed on our Forum. |
Beta Was this translation helpful? Give feedback.
-
|
We can not guarantee correct working in a threaded environment. The critical detail is the cache memory internally maintained by our base library MuPDF. |
Beta Was this translation helpful? Give feedback.
If you absolutely need parallel processing you should fallback to the multiprocessing module. Every process would have its own copy of MuPDF cache.