-
Notifications
You must be signed in to change notification settings - Fork 57
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
free tree on AsdfFile.close #1575
Conversation
@@ -449,6 +449,9 @@ def close(self): | |||
self._fd.close() | |||
self._fd = None | |||
self._closed = True | |||
# as we're closing the file, also empty out the | |||
# tree so that references to array data can be released | |||
self._tree = AsdfObject() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about raising a relevant error when the tree of a closed AsdfFile is accessed? I'd prefer a message like "Sorry your AsdfFile is closed" to "KeyError" if I were investigating a bug in my code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A custom exception sounds like a great idea. Currently and OSError
is raised so any custom exception we raise could inherit from that exception class for backwards compatibility.
Lines 559 to 561 in b43b2c5
if self._closed: | |
msg = "Cannot access data from closed ASDF file" | |
raise OSError(msg) |
It might make sense to raise the same error type when a block is accessed from a closed file (and any other places where access to a closed file is prevented):
Lines 1290 to 1292 in b43b2c5
if self._fd.is_closed(): | |
msg = "ASDF file has already been closed. Can not get the data." | |
raise OSError(msg) |
Perhaps a
ClosedFileAccess
exception that inherits from OSerror
? That seems reasonably backwards compatible to include in 3.0 (and would work towards cleaning up the rather generic exceptions raised by asdf).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, oops, I didn't notice/remember that we already throw an exception. OSError
is plenty enough for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
With these changes, when an AsdfFile object is closed the tree (which already could not be accessed because of the tree property gatekeeping) is set to a blank AsdfObject. This allows the garbage collector to clean up objects referenced in the tree even though the AsdfFile object does not fall out of scope. Fixes asdf-format#1558
With these changes, when an AsdfFile object is closed the tree (which already could not be accessed because of the tree property gatekeeping) is set to a blank AsdfObject.
This allows the garbage collector to clean up objects referenced in the tree even though the AsdfFile object does not fall out of scope.
Fixes #1558