Skip to content

Commit 4c36a0c

Browse files
authored
Avoid a crash when there is a timeout when shutting down the Dask cluster (#2580)
1 parent 0f9e888 commit 4c36a0c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

esmvalcore/config/_dask.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,11 @@ def get_distributed_client():
8080
if client is not None:
8181
client.close()
8282
if cluster is not None:
83-
cluster.close()
83+
try:
84+
cluster.close()
85+
except TimeoutError:
86+
logger.warning(
87+
"Timeout while trying to shut down the cluster at %s, "
88+
"you may want to check it was stopped.",
89+
cluster.scheduler_address,
90+
)

tests/unit/config/test_dask.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def test_get_distributed_client_external(mocker, tmp_path, warn_unused_args):
3737
mock_client.close.assert_called()
3838

3939

40-
def test_get_distributed_client_slurm(mocker, tmp_path):
40+
@pytest.mark.parametrize("shutdown_timeout", [False, True])
41+
def test_get_distributed_client_slurm(mocker, tmp_path, shutdown_timeout):
4142
cfg = {
4243
"cluster": {
4344
"type": "dask_jobqueue.SLURMCluster",
@@ -66,10 +67,12 @@ def test_get_distributed_client_slurm(mocker, tmp_path):
6667
create_autospec=True,
6768
return_value=mock_module,
6869
)
70+
mock_cluster = mock_cluster_cls.return_value
71+
if shutdown_timeout:
72+
mock_cluster.close.side_effect = TimeoutError
6973
with _dask.get_distributed_client() as client:
7074
assert client is mock_client
7175
mock_client.close.assert_called()
72-
mock_cluster = mock_cluster_cls.return_value
7376
_dask.Client.assert_called_with(address=mock_cluster.scheduler_address)
7477
args = {k: v for k, v in cfg["cluster"].items() if k != "type"}
7578
mock_cluster_cls.assert_called_with(**args)

0 commit comments

Comments
 (0)