Skip to content
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
11 changes: 10 additions & 1 deletion pkg-py/src/commons/_execution/_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
_KEEP = ("PATH", "LANG", "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH")


def worker_env(scratch_dir: str) -> dict[str, str]:
def worker_env(scratch_dir: str, *, single_thread: bool = False) -> dict[str, str]:
"""Build the worker's environment from an allowlist of the parent's.

``scratch_dir`` must be an absolute path; it becomes the worker's
``HOME`` and ``TMPDIR``, and a relative or empty value would silently
weaken the guarantee those two provide.

``single_thread`` pins the numerical thread pools, which the
user-namespace sandbox needs because it cannot be engaged by a process
that has already started one. ``needs_single_thread()`` decides.
"""
if not os.path.isabs(scratch_dir):
raise ValueError(f"scratch_dir must be an absolute path, got {scratch_dir!r}")
Expand All @@ -40,6 +44,11 @@ def worker_env(scratch_dir: str) -> dict[str, str]:
# of the user's dot files.
env["HOME"] = scratch_dir
env["TMPDIR"] = scratch_dir
if single_thread:
# Values commons chooses rather than parent variables it passes on,
# so they are set here rather than added to the allowlist.
env["OPENBLAS_NUM_THREADS"] = "1"
env["OMP_NUM_THREADS"] = "1"
return env


Expand Down
Loading
Loading