Skip to content

Make sure proc file is closed when reading#111

Merged
ktbarrett merged 1 commit intoktbarrett:masterfrom
anuraaga:close-proc-file
Feb 6, 2026
Merged

Make sure proc file is closed when reading#111
ktbarrett merged 1 commit intoktbarrett:masterfrom
anuraaga:close-proc-file

Conversation

@anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Feb 6, 2026

When running pytest against code that calls this library with strict warnings enabled, it fails due to proc being opened without close. In practice, I think readlines may be enough to close a file, but the ResourceWarning should still be avoided I guess.

https://github.com/connectrpc/connect-python/actions/runs/21719459903/job/62644711295?pr=118

    | Traceback (most recent call last):
    |   File "/home/runner/work/connect-python/connect-python/.venv/lib/python3.11/site-packages/find_libpython/__init__.py", line 150, in _get_proc_library
    |     lines = open(path).readlines()
    |             ^^^^^^^^^^^^^^^^^^^^^^
    | ResourceWarning: unclosed file <_io.TextIOWrapper name='/proc/2441/maps' mode='r' encoding='UTF-8'>
    | 
    | The above exception was the direct cause of the following exception:
    | 
    | Traceback (most recent call last):
    |   File "/home/runner/work/connect-python/connect-python/.venv/lib/python3.11/site-packages/_pytest/unraisableexception.py", line 67, in collect_unraisable
    |     warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
    | pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO name='/proc/2441/maps' mode='rb' closefd=True>
    | Enable tracemalloc to get traceback where the object was allocated.
    | See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

@codecov-commenter
Copy link

codecov-commenter commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.14%. Comparing base (a5a8f72) to head (5b0c60c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #111      +/-   ##
==========================================
+ Coverage   66.98%   67.14%   +0.15%     
==========================================
  Files           3        3              
  Lines         209      210       +1     
  Branches       51       51              
==========================================
+ Hits          140      141       +1     
  Misses         51       51              
  Partials       18       18              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ktbarrett ktbarrett merged commit 3fa5fd5 into ktbarrett:master Feb 6, 2026
17 checks passed
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.

3 participants