Skip to content

Commit

Permalink
force single threaded mode (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion authored Nov 19, 2016
1 parent 7f1fa11 commit 605620d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 7 additions & 0 deletions salem/sio.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def __call__(self, func):
xr.register_dataset_accessor = NullDecl
xr.register_dataarray_accessor = NullDecl
NetCDF4DataStore = object
try:
import dask
except ImportError:
pass


def read_shapefile(fpath, cached=False):
Expand Down Expand Up @@ -970,6 +974,9 @@ def open_mf_wrf_dataset(paths, chunks=None, compat='no_conflicts', lock=None,
if not paths:
raise IOError('no files to open')

# TODO: current workaround to dask thread problems
dask.set_options(get=dask.async.get_sync)

if lock is None:
lock = _default_lock(paths[0], 'netcdf4')
datasets = [open_wrf_dataset(p, chunks=chunks or {}, lock=lock)
Expand Down
11 changes: 1 addition & 10 deletions salem/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,16 +842,7 @@ def test_mf_datasets(self):
dss.close()
ds = sio.open_wrf_dataset(f)

def preprocess(ds):
# TODO: thread safety issues
vns = ['GEOPOTENTIAL', 'RAINNC', 'RAINC', 'T2C']
ds = ds[vns]
for vn in vns:
ds[vn] = ds[vn].load()
return ds

dsm = sio.open_mf_wrf_dataset(os.path.join(testdir, 'wrf_slice_*.nc'),
preprocess=preprocess)
dsm = sio.open_mf_wrf_dataset(os.path.join(testdir, 'wrf_slice_*.nc'))

assert_allclose(ds['RAINNC'], dsm['RAINNC'])
assert_allclose(ds['GEOPOTENTIAL'], dsm['GEOPOTENTIAL'])
Expand Down

0 comments on commit 605620d

Please sign in to comment.