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

BUG: ResourceWarnings for unclosed files in boxlib frontend #4890

Open
yut23 opened this issue Apr 30, 2024 · 2 comments · May be fixed by #4891
Open

BUG: ResourceWarnings for unclosed files in boxlib frontend #4890

yut23 opened this issue Apr 30, 2024 · 2 comments · May be fixed by #4891
Labels
Milestone

Comments

@yut23
Copy link
Member

yut23 commented Apr 30, 2024

Bug report

Bug summary

open() is used several times in the boxlib frontend without closing the files, triggering a ResourceWarning when the files go out of scope. Originally noticed by @neutrinoceros in #4845 (comment).

Code for reproduction

Standalone reproducer using the ParticleCavity dataset:

import warnings
import yt

# enable all warnings
warnings.simplefilter("default")
ds = yt.load("plt.Cavity00010")

Actual outcome

/home/eric/build/yt/yt/frontends/boxlib/data_structures.py:701: ResourceWarning: unclosed file <_io.TextIOWrapper name='/scratch/yt-data/plt.Cavity00010/inputs' mode='r' encoding='UTF-8'>
  lines = [line.lower() for line in open(cparam_filepath).readlines()]
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/home/eric/build/yt/yt/frontends/boxlib/data_structures.py:728: ResourceWarning: unclosed file <_io.TextIOWrapper name='/scratch/yt-data/plt.Cavity00010/Header' mode='r' encoding='UTF-8'>
  self._parse_header_file()
ResourceWarning: Enable tracemalloc to get the object allocation traceback
yt : [INFO     ] 2024-04-30 14:59:50,921 Parameters: current_time              = 0.017408426036316
yt : [INFO     ] 2024-04-30 14:59:50,921 Parameters: domain_dimensions         = [16 16  1]
yt : [INFO     ] 2024-04-30 14:59:50,921 Parameters: domain_left_edge          = [0. 0. 0.]
yt : [INFO     ] 2024-04-30 14:59:50,922 Parameters: domain_right_edge         = [1. 1. 1.]

Expected outcome

No warnings.

Version Information

  • yt version: 4.4.dev0, cd4f1d6 (current git head)
yut23 added a commit to yut23/yt that referenced this issue May 1, 2024
Manually close all the header and parameter files that are opened
outside a `with` statement.

Fixes yt-project#4890.
@yut23
Copy link
Member Author

yut23 commented May 1, 2024

I misunderstood the problem that @neutrinoceros raised in his comment. As noted in conftest.py, we explicitly ignore this class of warnings during tests, and they're ignored by default during normal usage. I'm leaving the PR open, as closing the files is probably a good idea anyways.

@yut23 yut23 closed this as completed May 1, 2024
@neutrinoceros
Copy link
Member

Interesting. I didn't mean to suggest that the problem existed on main, but maybe it does, and in that case it cannot be a blocker to #4845. Your PR clearly shows that's indeed the current state so I suggest we keep this open too.

@neutrinoceros neutrinoceros reopened this May 1, 2024
@neutrinoceros neutrinoceros added this to the 4.4.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants