Subprocess¶
Run shell commands through a stdlib-compatible API.
pulsing.subprocess mirrors Python's subprocess module and adds an optional
Pulsing-backed execution path when you want to attach resource requirements.
Run¶
python examples/python/subprocess_example.py
python examples/python/subprocess_example.py --resources
USE_POLSING_SUBPROCESS=1 python examples/python/subprocess_example.py --resources
Backend Selection¶
- Without
resources, calls go directly to Python's nativesubprocess. - With
resources=...but withoutUSE_POLSING_SUBPROCESS=1, the example still uses the native backend. - Only when both
resourcesis provided andUSE_POLSING_SUBPROCESS=1is set does execution switch to the Pulsing backend.
Code¶
import pulsing.subprocess as subprocess
PIPE = subprocess.PIPE
extra = {"resources": {"num_cpus": 2}}
result = subprocess.run(
["echo", "hello from run()"],
capture_output=True,
text=True,
check=True,
**extra,
)
proc = subprocess.Popen(["cat"], stdin=PIPE, stdout=PIPE, text=True, **extra)
stdout, _ = proc.communicate(input="pipe test")
The full example also covers:
check_output()for one-shot command capturePopen(...).communicate()with stdin/stdout/stderrTimeoutExpiredhandling- Multi-turn shell sessions through a persistent
/bin/sh
Key Points¶
- Import it as
import pulsing.subprocess as subprocessto keep the same calling style as the stdlib. - The resource-backed path is opt-in, so existing
subprocess-style code can migrate incrementally. - In resource-backed mode, Pulsing is initialized lazily by the module itself.