Skip to content

Fix unclosed file warnings #53

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lucduron
Copy link
Collaborator

No description provided.

@lucduron
Copy link
Collaborator Author

Here is a script to display warnings:

import xarray as xr

from xarray_selafin.xarray_backend import SelafinBackendEntrypoint

import warnings
warnings.simplefilter("default")

slf_in = "tests/data/r3d_tidal_flats.slf"
ds = xr.open_dataset(slf_in, engine=SelafinBackendEntrypoint)
ds.selafin.write("OUT.slf")
ds.close()

The generated output:

ResourceWarning: unclosed file <_io.BufferedWriter name='OUT.slf'>
  write_serafin(filepath, ds)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='tests/data/r3d_tidal_flats.slf'>

It shows that without this PR, there are 2 warnings:

  • on the opened file to read
  • on the opened file to write

Copy link
Contributor

@tomsail tomsail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one looks good to me.
@pmav99 do you have any comments on the tests?

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.

2 participants