Skip to content
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

Adds cwd propagation to DaskExecutor #994

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
if: ${{ matrix.executors == 'dask' && matrix.python-version != '3.8' }}
run: |
cd tests
PYTEST_EXECUTORS=dask poetry run python -m pytest -sv test_all.py
PYTEST_EXECUTORS=dask poetry run python -m pytest -sv test_all.py test_dask.py

webknossos_linux:
needs: changes
Expand Down
1 change: 1 addition & 0 deletions cluster_tools/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For upgrade instructions, please check the respective *Breaking Changes* section
### Changed

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


## [0.14.14](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.14.14) - 2024-01-12
Expand Down
7 changes: 6 additions & 1 deletion cluster_tools/cluster_tools/executors/dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def _run_in_nanny(
for key, value in __env.items():
os.environ[key] = value

print(os.environ["PWD"])
normanrz marked this conversation as resolved.
Show resolved Hide resolved
if "PWD" in os.environ:
os.chdir(os.environ["PWD"])
ret = __fn(*args, **kwargs)
queue.put({"value": ret})
except Exception as exc:
Expand Down Expand Up @@ -174,7 +177,9 @@ def submit( # type: ignore[override]
),
)

kwargs["__env"] = os.environ.copy()
__env = os.environ.copy()
__env["PWD"] = os.getcwd()
kwargs["__env"] = __env

# We run the functions in dask as a separate process to not hold the
# GIL for too long, because dask workers need to be able to communicate
Expand Down
29 changes: 29 additions & 0 deletions cluster_tools/tests/test_dask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
from typing import TYPE_CHECKING, List, Optional

if TYPE_CHECKING:
from distributed import LocalCluster

import cluster_tools

_dask_cluster: Optional["LocalCluster"] = None


def job(_arg: None) -> str:
return os.getcwd()


def test_pass_cwd() -> None:
global _dask_cluster
if not _dask_cluster:
from distributed import LocalCluster, Worker

_dask_cluster = LocalCluster(
worker_class=Worker, resources={"mem": 20e9, "cpus": 4}, nthreads=6
)
with cluster_tools.get_executor(
"dask", job_resources={"address": _dask_cluster}
) as exec:
tmp_path = os.path.realpath("/tmp") # macOS redirects `/tmp` to `/private/tmp`
os.chdir(tmp_path)
assert list(exec.map(job, [None])) == [tmp_path]
Loading