-
-
Notifications
You must be signed in to change notification settings - Fork 217
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
Would it make sense to support the context-manager protocol in skyfield.api.load_file()? #374
Comments
The underlying
Would that work for your use case? I’m hesitant to add too much code to satisfy a mere testing mechanism, in a case where no actual users have yet reported real problems. |
That would be awesome---thanks. And you're right, this is not a real problem by any measure, it's really only a small thing that I noticed testing. |
Great! Let's leave the issue open til there's a chance to implement it. In the meantime, I think your tests can call
|
Now that I think about it, I'd say that, had I found the snippet above in the docs, I wouldn't have opened this issue in the first place. (And I apologize in advance if it's there already and I missed it.) So maybe adding some direction in the docs is really everything that one needs? |
It should certainly be mentioned in the docs, yes, and no you didn’t miss it — no one had ever asked, and I had not thought of putting it there myself. When I get around to adding the docs, I'll see if I also feel inspired to make it more convenient than it currently is :) |
I might be missing something fundamental---in which case I apologize in advance---but I just noticed a resource warning in my unit tests
sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='/data/work/ixpe/ixpeobssim/ixpeobssim/instrument/data/de430t_2000_2040.bsp'> make[1]: Leaving directory '/data/work/ixpe/ixpeobssim/tests'
and I realize that I don't have control (I think) on the files open by skyfield.
Would it make sense to implement the context-manager protocol, so that instead of writing
planets = skyfield.api.load_file(ephem_file_path)
I would do
with skyfield.api.load_file(ephem_file_path) as planets: do something
and have the file closed automatically at the exit of the with block?
The text was updated successfully, but these errors were encountered: