netcdf4-python
netcdf4-python copied to clipboard
Seg fault when opening the same file twice, even in read mode
Minimal example
The problem was initially raised as an issue on pydata/xarray and a MWE can be found here.
Problem description
Currently a seg fault is thrown under certain circumstances when a xarray dataset is opened and converted to a pandas dataframe. The seg fault can be avoided by closing and opening the netcdf file between reading in each group.
Desired outcome
Ideally netCDF4-Python would avoid the segfault or at least catch these cases and raise a Python error rather than a segfault (which obviously is hard to recover from).
Is it possible to distill the minimal example further so that it depends only on netCDF4 (not xarray and pandas)?
I'm afraid I don't have enough of an understanding of/experience with what's going on behind the scenes to know how to distill the problem further. Sorry.
@TomFarley which version of netCDF4 are you using?
Something simple like this does not segfault for me
>>> import netCDF4
>>> a = netCDF4.Dataset('test.nc', 'r')
>>> b = netCDF4.Dataset('test.nc', 'r')
>>> netCDF4.__version__
'1.3.1'
I'm using version 1.3.1. The simple test you suggest @akrherz works fine for me too.