Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have now encountered several issues concerning
roman_datamodels
closing there associated ASDF file unexpectedly and/or unreliably. These issues tend to be extremely difficult to debug as the bugs cannot be consistently replicated. In the majority of cases these issues are caused by the fact that there is aDataModel.__del__
method which triggers the closure of the associated ASDF file if there is one. This method is "called" whenever a given object's reference count drops to zero, and in this case it is improperly being used as a "destructor".The issue with comes with the fact that the ASDF file opened and held by the
DataModel
itself references theDataModel
which creates a reference cycle. Thus in this caseDataModel.__del__
is only called on a given instance by the garbage collector not when its apparent reference count drops to zero. Consequently, we cannot guarantee when/ifDataModel.__del__
is successfully called on a givenDataModel
instance. This ambiguity can lead to issues where sometimes operations which reference data in the ASDF file work and sometimes they do not, the root of which is when the Python garbage collector actually gets run during a particular program execution instance.Note that the reason why
DataModel.__del__
exists the way that it does is so that usage ofDataModels
should not leave behind open files. While this is important, the inherent inconsistencies with the approach of usingDataModel.__del__
create's more issues than it solves. Instead, eitherDataModel.__del__
should be removed.Datamodel.__del__
should raise an error if the ASDF file is still open.Currently, this PR removes
DataModel.__del__
.Note that to avoid issues with
DataModels
and file handles we really should make theroman_datamodels.open
method a proper context manager instead of just a function, so that it explicitly cleans up theDataModel
whenever it exits AND resolve any open file warnings/errors we encounter during testing.Checklist
CHANGES.rst
under the corresponding subsection