Fix ahi_hsd cleanup during interpreter shutdown
I get the following warning when reading bzipped AHI HSD files
Exception ignored in: <function AHIHSDFileHandler.__del__ at 0x7f5fff886200>
Traceback (most recent call last):
File ".../satpy/readers/ahi_hsd.py", line 409, in __del__
AttributeError: 'NoneType' object has no attribute 'path'
This is because the os module is set to None during interpreter shutdown. From the docs:
del() can be executed during interpreter shutdown. As a consequence, the global variables it needs to access (including other modules) may already have been deleted or set to None
I followed the advice in the docs and registered the cleanup using weakref.finalize.
Looking at the documentation, I don't see it clearly written that weakref.finalize would solve the problem you mention. Could you verify yourself that it does indeed work?
Yes, with finalizer the warnings are gone. Did you see that section in the documentation?
A finalizer will never invoke its callback during the later part of the interpreter shutdown when module globals are liable to have been replaced by None.
no, but I'm probably looking in the wrong place :) https://docs.python.org/3/reference/datamodel.html#object.del
Oh, sorry that's from https://docs.python.org/3/library/weakref.html#weakref.finalize
Thanks for the link, I understand what finalize does here, so LGTM! I have to admit I'm a bit disappointed by __del__'s behaviour :) or I don't understand what it is for.