autonlab / audata

GNU Lesser General Public License v3.0
5 stars 0 forks source link

Automatic file closure on termination #7

Closed guswelter closed 3 years ago

guswelter commented 3 years ago

If a Python script terminates without closing an audata file, the following output is observed:

Exception ignored in: <function File.__del__ at 0x7f9cc296a700>
Traceback (most recent call last):
  File "/ihome/gclermont/gwelter/miniconda3/envs/auv/lib/python3.8/site-packages/audata/file.py", line 80, in __del__
  File "/ihome/gclermont/gwelter/miniconda3/envs/auv/lib/python3.8/site-packages/audata/file.py", line 206, in close
  File "/ihome/gclermont/gwelter/miniconda3/envs/auv/lib/python3.8/site-packages/h5py/_hl/files.py", line 432, in close
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5f.pyx", line 267, in h5py.h5f.get_obj_ids
  File "h5py/h5i.pyx", line 37, in h5py.h5i.wrap_identifier
ImportError: sys.meta_path is None, Python is likely shutting down

This output is not observed if the file is close (e.g. f.close()) before script termination. Please implement auto-closure of files such that an exception like this is not observed if the file can be automatically closed properly.

vedant-sanil commented 3 years ago

Resolved. It appears this issue comes because the underlying self.hdf.close() is called after h5py runs its own garbage collector. This also why the issue presents only when audata.file.File's garbage collector method is called.