-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hangs while saving netcdf file opened using xr.open_mfdataset with lock=None #3961
Comments
xr.open_mfdataset
with lock=None
Thanks @jessicaaustin. We have run into the same issue. Setting lock=False works, but as hdf5 is not thread safe, we are not sure if this could have unexpected consequences. Edit: Actually, I have checked, and the hdf5 version we are using (from conda-forge) is build in thread safe mode. This means that concurrent reads are possible, and that the lock=False in open_mfdataset would be safe. In fact it is more efficient as it does not make sense to handle locks if hdf5 is already thread safe. Am I right? |
Using:
I have experienced this issue as well when writing netcdf using |
Using:
I am experiencing same when trying to write netcdf file using xr.to_netcdf() on a files opened via xr.open_mfdataset with lock=None. Then I tried OP's suggestion and it worked like a charm BUT Now I am facing different issue. Seems that hdf5 IS NOT thread safe, since I encounter NetCDF: HDF error while applying different function on a netcdf file, previously were processed by another function with lock=False. This is the BIGGEST issue and needs resolve ASAP |
I have the same issue as well and it appears to me that Ubuntu system is more prone to this issue vs. CentOS. Wondering if anyone else has a similar experience |
I have the same behaviour with MacOS (10.15). xarray=0.16.1, dask=2.30.0, netcdf4=1.5.4. Sometimes saves, sometimes doesn't. |
Lock false sometimes throws hd5 error. No clear solution. The only solution I have found, sleep method for 1 second |
I haven't seen that yet, but I'd still far prefer an occasional error to a hung process. |
Just adding my +1 here, and also mention that (if memory allows), |
Also seeing this as of version 0.16.1. In some cases, I need In other cases, I need Is the current recommended solution to set |
Or alternatively you can try to set sleep between openings. When you try to open same file from different functions with different operations, it is better to keep file opening function wrapped with a 1 second delay/sleep rather than direct open |
To clarify, do you mean adding a sleep of e.g. 1 second prior to your Is this solution only addressing the issue of opening the same ds multiple times within a python process, or would it also address multiple processes opening the same ds? |
Please make some dummy tests, I did time.sleep, prior every operation. This was the only workaround that really worked. |
Issue also described and tracked in pydata/xarray#3961.
Issue also described and tracked in pydata/xarray#3961.
* test(gen_agg): create dummy files and execute stuff * test(gen_agg): stuff is working Next: add feat to gen_agg so that files can be appended. * test(gen_agg): split into many generated files The time span attribute is moved to the global attribute of the dataset, which makes it so it is transferred over to the history field of the new concatenated file when using `ncrcat`. * perf(close): close all opened datasets in gen_agg (#15) * fix(nc_savefile): open in lock=False mode (#16) Issue also described and tracked in pydata/xarray#3961. * test(gen_agg): test against different netCDF formats All file formats supported by xarray now works in the tests. Good stuff. * ci: set up workflows for labeler and release draft (#19)
Any progress in solving this problem?
|
I am testing out code that uses xarray to process netcdf files, in particular to join multiple netcdf files into one along shared dimensions. This was working well, except sometimes when saving the netcdf file the process would hang.
I was able to whittle it down to this simple example: https://github.com/jessicaaustin/xarray_netcdf_hanging_issue
This is the code snippet at the core of the example:
If you run this once, it's typically fine. But run it over and over again in a loop, and it'll eventually hang on
mfd.to_netcdf
. However if I setlock=False
then it runs fine every time.I've seen this with the following combos:
and
And I've tried it with different netcdf files and different computers.
Versions
Output of `xr.show_versions()`
INSTALLED VERSIONS
commit: None
python: 3.7.6 | packaged by conda-forge | (default, Mar 23 2020, 23:03:20)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 4.15.0-20-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.7.4
xarray: 0.15.1
pandas: 1.0.3
numpy: 1.18.1
scipy: None
netCDF4: 1.5.3
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.1.1.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2.14.0
distributed: 2.14.0
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
setuptools: 46.1.3.post20200325
pip: 20.0.2
conda: None
pytest: None
IPython: None
sphinx: None
The text was updated successfully, but these errors were encountered: