Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix strange ResourceWarning #231

Conversation

WilliamJamieson
Copy link
Contributor

@WilliamJamieson WilliamJamieson commented Jul 4, 2023

Closes #150

This PR should fix the seemingly "random" file handle left open errors. In a few cases the tests were not using a context manager nor calling close when opening a datamodel from a file.

While this normally calls the destructor __del__:

def __del__(self):
"""Ensure closure of resources when deleted."""
self.close()

When the model in question goes out of scope, this is not ensured to happen immediately nor is in ensured to happen at the close of the interpreter, see the python docs. The seemingly "random" resource warning was detecting the cases where the models opened but not explicitly closed went out of scope, but the __del__ had not been called yet. This can occur for all sorts of arbitrary reasons during any given execution of the tests (e.g. system load, memory address space, etc).

Checklist

@codecov
Copy link

codecov bot commented Jul 4, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (ce423ee) 94.47% compared to head (6b0eb91) 94.47%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #231   +/-   ##
=======================================
  Coverage   94.47%   94.47%           
=======================================
  Files          23       23           
  Lines        1628     1628           
=======================================
  Hits         1538     1538           
  Misses         90       90           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@WilliamJamieson WilliamJamieson marked this pull request as ready for review July 4, 2023 02:02
@WilliamJamieson WilliamJamieson requested a review from a team as a code owner July 4, 2023 02:02
@WilliamJamieson WilliamJamieson merged commit c0a084d into spacetelescope:main Jul 6, 2023
15 checks passed
@WilliamJamieson WilliamJamieson deleted the bugfix/random_file_left_open branch July 6, 2023 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strange ResourceWarning
2 participants