Repository navigation
Conversation
If any exception occurs between fitz.open() and doc.close(), the document object is never closed, leaking a file descriptor. During batch PDF processing in the literature collection stage this can exhaust the OS file descriptor limit. Replace manual open/close with a `with` statement so the document is always closed, even on error. Made-with: Cursor
There was a problem hiding this comment.
Pull request overview
This PR prevents file descriptor leaks during PDF extraction by ensuring PyMuPDF documents are always closed, even when exceptions occur mid-extraction (important for batch PDF processing in the literature collection pipeline).
Changes:
- Replaced manual
fitz.open()/doc.close()handling with awith fitz.open(...) as doc:context manager inPDFExtractor.extract().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2 tasks done
3 tasks done
Author
|
Consolidated into #102 as requested. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extract_from_file()opens a PyMuPDF document withfitz.open()and callsdoc.close()at the endFix: Replace manual
open()/close()with awithcontext manager.Test plan
fitz.Documentsupports the context manager protocolwithblock (metadata variables captured before exit)