Closed jdavies-st closed 5 years ago
(And, let's ignore the Appveyor results for now; I'll see if I can remove them or get them working again soon.)
FWIW, we're using jplephem
over in the JWST pipeline code to do barycentric correction. And of course it is used in astropy
. In both cases, I believe the __enter__
and __exit__
functionality will come in handy. Many thanks!
This fixes an issue where the ephemeris file is left open because mmaps are not closed. This came up in the recent
astropy 3.1
release testing.This behavior can by simply reproduced by using
pytest
to run the unit tests and using thepytest-openfiles
plugin (available via pip install). Output below (trimmed for clarity):I've used
try/except
blocks to close the mmaps and references to them. I'm not sure this is the best way. I had originally coded it up with lots ofhasattr
checks. Would be happy to change if that is preferred.I've also added
__enter__
and__exit__
methods to theSPK
class so that it can be used with awith
context manager. Very simple and useful - one doesn't have to remember to explicitly callSPK.close()
in order to make sure the file gets closed. I've updated one of the tests to use thewith
context manager so this is covered.With these fixes, one can see that files are no longer left open: