Skip to content

Close hdf5 file in notebooks #2

@trey-stafford

Description

@trey-stafford

A suggestion:

In the basic_examples/001-open-raster-file.ipynb and basic_examples/003-combining-data-in-algorithm.ipynb notebooks, a SMAP h5 file is opened for reading. If one of these notebooks is run before the other, the user may run into problems opening the h5 dataset in the second notebook.

It appears that the h5 file becomes locked when it is first opened. This is the error I get when attempting to re-open the dataset a second time, without closing the first:

smap = SMAPH5(source='../../data/raster/SMAP_L4_SM_aup_20181027T090000_Vv4030_001.h5',
              nan_vals=[-9999],
              interpolation='bilinear')
smap.native_coordinates

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/miniconda3/envs/podpac/lib/python3.7/site-packages/traitlets/traitlets.py in get(self, obj, cls)
    527         try:
--> 528             value = obj._trait_values[self.name]
    529         except KeyError:

KeyError: 'dataset'

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
~/miniconda3/envs/podpac/lib/python3.7/site-packages/h5py/_hl/files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
    189         try:
--> 190             fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)
    191         except IOError:

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5f.pyx in h5py.h5f.open()

OSError: Unable to open file (unable to lock file, errno = 11, error message = 'Resource temporarily unavailable')
...

closing the first dataset resolves the problem:

smap.close_dataset()

It would be useful to add this close_dataset step at the end of each notebook that opens hdf5 files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions