Skip to content

Commit 81c84e0

Browse files
committed
Allow global worker root with ruff ignore
1 parent 0ddd1c3 commit 81c84e0

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/pytask_parallel/backends.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"set_worker_root",
3030
]
3131

32-
_WORKER_STATE: dict[str, str | None] = {"root": None}
32+
_WORKER_ROOT: str | None = None
3333

3434

3535
def set_worker_root(path: os.PathLike[str] | str) -> None:
@@ -41,7 +41,8 @@ def set_worker_root(path: os.PathLike[str] | str) -> None:
4141
4242
"""
4343
root = os.fspath(path)
44-
_WORKER_STATE["root"] = root
44+
global _WORKER_ROOT # noqa: PLW0603
45+
_WORKER_ROOT = root
4546
if root not in sys.path:
4647
sys.path.insert(0, root)
4748
# Ensure custom process backends can import task modules by reference.
@@ -118,7 +119,7 @@ def _get_loky_executor(n_workers: int) -> Executor:
118119
return get_reusable_executor(
119120
max_workers=n_workers,
120121
initializer=_configure_worker,
121-
initargs=(_WORKER_STATE["root"],),
122+
initargs=(_WORKER_ROOT,),
122123
)
123124

124125

@@ -127,7 +128,7 @@ def _get_process_pool_executor(n_workers: int) -> Executor:
127128
return _CloudpickleProcessPoolExecutor(
128129
max_workers=n_workers,
129130
initializer=_configure_worker,
130-
initargs=(_WORKER_STATE["root"],),
131+
initargs=(_WORKER_ROOT,),
131132
)
132133

133134

0 commit comments

Comments
 (0)