I am using python2.7 to handle input/output files in GRIB and netCDF format. The code is such that it can read data from both GRIB and netCDF format and write in the format chosen by the user. The del destructor is called to free up the memory. My destructor looks like this:
def __del__(self):
""" netCDF : delete the init files and close the dataset
grib : release grib message (self.msg exists only for GRIB files)
"""
# GRIB
if self.msg :
ga.grib_release(self.msg)
# netCDF
else:
self.dataset.close()
try :
if os.path.isfile(self.fileName):
os.remove(self.fileName)
except :
pass
Using this destructor slows down may code after few iterations. If I comment out the part for GRIB (when I am using netCDF) or vice-versa, the code runs normally. But using the if loop makes the code very very slow after reading/writing maybe 15 files. Could anyone help me point out the mistake I might be making!