Skip to content

Fix ResourceWarning leak for internally opened streams#1364

Closed
ReinerBRO wants to merge 1 commit into
jsvine:stablefrom
ReinerBRO:fix/resourcewarning-finalizer
Closed

Fix ResourceWarning leak for internally opened streams#1364
ReinerBRO wants to merge 1 commit into
jsvine:stablefrom
ReinerBRO:fix/resourcewarning-finalizer

Conversation

@ReinerBRO
Copy link
Copy Markdown

Summary

  • register a finalizer to close internally-opened PDF streams if a PDF object is garbage collected without an explicit close
  • keep externally provided streams untouched
  • add a regression test covering the ResourceWarning leak and external-stream behavior

Why

Issue #1336 reports that file handles opened by pdfplumber.open(path) can survive until garbage collection and emit a ResourceWarning. This change ensures internally owned streams are still closed if callers forget to use a context manager or call close().

Tests

  • . .venv/bin/activate && python -m pytest tests/test_resource_warning.py -q

Closes #1336

@ReinerBRO
Copy link
Copy Markdown
Author

Closing this duplicate PR in favor of #1363, which carries the same commit and targets the intended branch for review.

@ReinerBRO ReinerBRO closed this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Input file handle is never closed, causing a ResourceWarning in Python 3.11+

1 participant