Skip to content

Commit 0d9dea8

Browse files
authored
Merge pull request #75 from martindurant/procs
Add clarity around (server) subprocesses
2 parents accb620 + c48efb1 commit 0d9dea8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/projspec/artifact/process.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class Process(BaseArtifact):
3333
"""A simple process where we know nothing about what it does, only if it's running.
3434
3535
Can include batch jobs and long-running services.
36+
37+
While running the process, the output can be "enqueued", meaning that
38+
the .queue attribute will be populated with lines of output (from
39+
stdout and stderr, by default). This can be controlled by passing
40+
`enqueue=` to the .make() method; or disabled by setting the config
41+
value `capture_artifact_output` to False.
3642
"""
3743

3844
term: bool = False
@@ -52,6 +58,8 @@ def _make(self, enqueue=True, **kwargs):
5258
kwargs["stdout"] = subprocess.PIPE
5359
kwargs["stderr"] = subprocess.STDOUT
5460
kwargs["close_fds"] = ON_POSIX
61+
else:
62+
kwargs["output"] = False
5563
proc = run_subprocess(
5664
self.cmd,
5765
cwd=self.proj.url,

src/projspec/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,10 @@ def run_subprocess(cmd, cwd=None, env=None, output=True, popen=False, **kwargs):
221221

222222
raise RuntimeError(f"Not installed: {suggest(cmd[0])}")
223223
if popen:
224-
kwargs.setdefault("stdout", subprocess.PIPE)
225-
kwargs.setdefault("stderr", subprocess.STDOUT)
224+
if "stdout" not in kwargs and output:
225+
kwargs["stdout"] = subprocess.PIPE
226+
if "stderr" not in kwargs and output:
227+
kwargs["stderr"] = subprocess.STDOUT
226228
return subprocess.Popen(cmd, cwd=cwd, env=env, **kwargs)
227229
# returns CompletedProcess with stdout, stderr as attributes
228230
if "stdout" not in kwargs and "stderr" not in kwargs:

0 commit comments

Comments
 (0)