ngageoint / sarpy

A basic Python library to demonstrate reading, writing, display, and simple processing of complex SAR data using the NGA SICD standard.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

explicit gc.collect() fails at shutdown

kjurka opened this issue · comments

When processing SICD imagery and our process ends we get an error with sarpy master:

Exception ignored in: <function NITFReader.__del__ at 0x7fbd4aecfee0>
Traceback (most recent call last):
  File "/home/kjurka/git/sarpy/sarpy/io/general/nitf.py", line 1697, in __del__
TypeError: 'NoneType' object is not callable

This error is ignored, so it doesn't have any functional impact, but it looks a little scary to people.

gc.collect()

So at shutdown we've already freed the "gc" module and now we're in the SICDReader's parent destructor and the gc.collect() call fails as gc no longer exists. I haven't been able to reproduce this with a simple script, but I'm curious why sarpy is making explicit garbage collection calls in the first place. I wouldn't have thought that appropriate for a library. Checking git blame does not provide any clues.

12d693c

Can you provide any insight as to why this is necessary or if it would be silly to check

if gc is not None:
  gc.collect()

I am responsible for essentially the entire library, so git blame will pretty much always indicate me.

I agree that this is unusual, and I tried to avoid it. I inserted this call to the garbage collector to try to alleviate another problem observed by another set of people - it's hard to guarantee that writing to a chip is actually done. I think that the trouble being observed was really OS/file system specific, and I think that the only way to guarantee that writing to the chip is actually finished is to garbage collect the responsible object - applying del, which just marks it for garbage collection, is not enough.

Note that gc itself is not None, but evidently gc.collect is None. It would not be silly to check for that state, and I will do so.