Skip to content

Commit 6549c70

Browse files
normanrzdaniel-wer
andauthored
Adds cwd propagation to DaskExecutor (#994)
* Adds cwd propagation to DaskExecutor * changelog * add test_dask to CI * Update cluster_tools/cluster_tools/executors/dask.py Co-authored-by: Daniel <[email protected]> --------- Co-authored-by: Daniel <[email protected]>
1 parent afdad65 commit 6549c70

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
if: ${{ matrix.executors == 'dask' && matrix.python-version != '3.8' }}
135135
run: |
136136
cd tests
137-
PYTEST_EXECUTORS=dask poetry run python -m pytest -sv test_all.py
137+
PYTEST_EXECUTORS=dask poetry run python -m pytest -sv test_all.py test_dask.py
138138
139139
webknossos_linux:
140140
needs: changes

cluster_tools/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ For upgrade instructions, please check the respective *Breaking Changes* section
1616
### Changed
1717

1818
### Fixed
19+
- Fixed working directory propagation in DaskExecutor. [#994](https://github.com/scalableminds/webknossos-libs/pull/994)
1920

2021

2122
## [0.14.14](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.14.14) - 2024-01-12

cluster_tools/cluster_tools/executors/dask.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def _run_in_nanny(
4141
for key, value in __env.items():
4242
os.environ[key] = value
4343

44+
if "PWD" in os.environ:
45+
os.chdir(os.environ["PWD"])
4446
ret = __fn(*args, **kwargs)
4547
queue.put({"value": ret})
4648
except Exception as exc:
@@ -174,7 +176,9 @@ def submit( # type: ignore[override]
174176
),
175177
)
176178

177-
kwargs["__env"] = os.environ.copy()
179+
__env = os.environ.copy()
180+
__env["PWD"] = os.getcwd()
181+
kwargs["__env"] = __env
178182

179183
# We run the functions in dask as a separate process to not hold the
180184
# GIL for too long, because dask workers need to be able to communicate

cluster_tools/tests/test_dask.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
from typing import TYPE_CHECKING, List, Optional
3+
4+
if TYPE_CHECKING:
5+
from distributed import LocalCluster
6+
7+
import cluster_tools
8+
9+
_dask_cluster: Optional["LocalCluster"] = None
10+
11+
12+
def job(_arg: None) -> str:
13+
return os.getcwd()
14+
15+
16+
def test_pass_cwd() -> None:
17+
global _dask_cluster
18+
if not _dask_cluster:
19+
from distributed import LocalCluster, Worker
20+
21+
_dask_cluster = LocalCluster(
22+
worker_class=Worker, resources={"mem": 20e9, "cpus": 4}, nthreads=6
23+
)
24+
with cluster_tools.get_executor(
25+
"dask", job_resources={"address": _dask_cluster}
26+
) as exec:
27+
tmp_path = os.path.realpath("/tmp") # macOS redirects `/tmp` to `/private/tmp`
28+
os.chdir(tmp_path)
29+
assert list(exec.map(job, [None])) == [tmp_path]

0 commit comments

Comments
 (0)