If we yield the Popen, we yield a context manager from a context
manager, which becomes hard to follow, since we'll only enter the
outer context manager, and not the inner Popen context manager. To
make things simpler, let's enter the Popen context manager in
spawn() itself.
stdout = sys.stderr
try:
- yield subprocess.Popen(
+ with subprocess.Popen(
cmdline,
stdin=stdin,
stdout=stdout,
pass_fds=pass_fds,
env=env,
preexec_fn=make_foreground_process if foreground else None,
- )
+ ) as proc:
+ yield proc
except FileNotFoundError:
die(f"{cmdline[0]} not found in PATH.")
except subprocess.CalledProcessError as e: