netcdf4-python icon indicating copy to clipboard operation
netcdf4-python copied to clipboard

Seg fault when opening the same file twice, even in read mode

Open TomFarley opened this issue 7 years ago • 4 comments

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).

TomFarley avatar Apr 27 '18 08:04 TomFarley

Is it possible to distill the minimal example further so that it depends only on netCDF4 (not xarray and pandas)?

jswhit avatar Apr 27 '18 15:04 jswhit

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 avatar Apr 27 '18 20:04 TomFarley

@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'

akrherz avatar Apr 27 '18 20:04 akrherz

I'm using version 1.3.1. The simple test you suggest @akrherz works fine for me too.

TomFarley avatar May 01 '18 08:05 TomFarley