-
Notifications
You must be signed in to change notification settings - Fork 262
Intent to deprecate: keep_file_open #573
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
Comments
Hey @effigies, I don't have any strong feelings either way about this, apart from wondering whether there might be some use case (or future file IO driver) which depends on having a persistent file handle. This is not a problem for me personally though. Happy to help out if this goes ahead too! |
I suppose that's a possibility, but I'm not sure what sort of case might exist where you couldn't emulate a persistently open filehandle by opening and seeking to last known location, prior to performing the operation. In fact, perhaps what we want to do to get the current releasing behavior is a simple pass-through filehandle like the following (not fully worked through): class ReleasingFileHandle:
def __init__(self, file_like):
self.file_like = file_like
self._pos = 0 if not hasattr(file_like, tell) else file_like.tell()
def _get_fileobj(self, mode):
if isinstance(self.file_like, str):
with open(self.file_like, mode) as fobj:
fobj.seek(self._pos)
yield fobj
self._pos = fobj.tell()
else:
yield self.file_like
def read(self, *args, **kwargs):
with self._get_fileobj() as fobj:
return fobj.read(*args, **kwargs)
... Then as far as This would be redoing work that's in I may not be thinking this through too clearly. As you've dug through these bits of code more thoroughly than I have, does this seem plausible, or can you think of some alternative? |
I do like your |
That might be the cleanest way of doing it. I had a brief look, but haven't had time to think carefully about how to do that. Feel free to push ahead, and I'll try to review. Otherwise I'll poke at it as I find time. |
Sure - I'm flying down under shortly so am quite busy, but I should have some time over the next couple of weeks. |
As of indexed_gzip 0.7.0, the default behavior of a
SafeIndexedGzipFile
is to close the underlying file between accesses. This pretty much obviates the machinery @pauldmccarthy built around thekeep_file_open
option in Opener, ArrayProxy, AnalyzeImage and MGHImage.As we did have a release, we're going to need to deprecate the API, but I think the following scheme should be reasonably safe:
indexed_gzip
version to 0.7.0keep_file_open
- it only had any effect ifindexed_gzip
was installed ANDkeep_file_open
was'auto'
orTrue
- and update docs to say "has no effect, will be removed vXXX"keep_file_open
raises aDeprecationWarning
if it is notNone
.arrayproxy.KEEP_FILE_OPEN_DEFAULT
- This one I'm not sure of. I think people would only be setting it, not reading it, but maybe it should stay just in case.What do y'all think?
The text was updated successfully, but these errors were encountered: