Skip to content

Additional updates for detecting a distributed scheduler #9890

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

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions dask/array/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3655,13 +3655,18 @@ def to_zarr(

if isinstance(url, zarr.Array):
z = url
if isinstance(z.store, (dict, MutableMapping)) and config.get(
"scheduler", ""
) in ("dask.distributed", "distributed"):
raise RuntimeError(
"Cannot store into in memory Zarr Array using "
"the Distributed Scheduler."
)
if isinstance(z.store, (dict, MutableMapping)):
try:
from distributed import default_client

default_client()
except (ImportError, ValueError):
pass
else:
raise RuntimeError(
"Cannot store into in memory Zarr Array using "
"the distributed scheduler."
)

if region is None:
arr = arr.rechunk(z.chunks)
Expand Down
9 changes: 9 additions & 0 deletions dask/dataframe/io/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,18 @@ def to_hdf(

# If user did not specify scheduler and write is sequential default to the
# sequential scheduler. otherwise let the _get method choose the scheduler
try:
from distributed import default_client

default_client()
client_available = True
except (ImportError, ValueError):
client_available = False

if (
scheduler is None
and not config.get("scheduler", None)
and not client_available
and single_node
and single_file
):
Expand Down
2 changes: 1 addition & 1 deletion dask/tests/test_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def test_zarr_in_memory_distributed_err(c):
a = da.ones((3, 3), chunks=chunks)
z = zarr.zeros_like(a, chunks=chunks)

with pytest.raises(RuntimeError):
with pytest.raises(RuntimeError, match="distributed scheduler"):
a.to_zarr(z)


Expand Down