fix: ensure PdfReader is closed#8636
Conversation
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Utils (parse_pdf_to_text)
participant File
participant PdfReader
Caller->>Utils (parse_pdf_to_text): Call with file_path
Utils (parse_pdf_to_text)->>File: Open file as context manager
Utils (parse_pdf_to_text)->>PdfReader: Instantiate as context manager with file
PdfReader-->>Utils (parse_pdf_to_text): Extract text
Utils (parse_pdf_to_text)->>File: Close file (automatically)
Utils (parse_pdf_to_text)->>PdfReader: Close reader (automatically)
Utils (parse_pdf_to_text)-->>Caller: Return extracted text
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
🔇 Additional comments (1)
|
ogabrielluiz
left a comment
There was a problem hiding this comment.
Thank you @roudy16 ! Good catch
This LGTM
The issue is that objects created by the PdfReader have a tendency to linger in memory.
I was memory profiling with
tracemallocmy use-case and noticed a lot of Pdf-related objects in the summary. After applying this change the objects didn't show up in the trace summary and my memory consumption post-run was reduced.Summary by CodeRabbit