# Buggy code
def run_subproc(cmds, captured=False):
    """Runs a subprocess, in its many forms. This takes a list of 'commands,'
    which may be a list of command line arguments or a string, representing
    a special connecting character.  For example::

        $ ls | grep wakka

    is represented by the following cmds::

        [['ls'], '|', ['grep', 'wakka']]

    Lastly, the captured argument affects only the last real command.
    """
    specs = cmds_to_specs(cmds, captured=captured)
    captured = specs[-1].captured
    procs = []
    proc = pipeline_group = None
    for spec in specs:
        starttime = time.time()
        proc = spec.run(pipeline_group=pipeline_group)
        procs.append(proc)
        if ON_POSIX and pipeline_group is None and spec.cls is subprocess.Popen:
            pipeline_group = proc.pid
    if not spec.is_proxy:
        add_job(
            {
                "cmds": cmds,
                "pids": [i.pid for i in procs],
                "obj": proc,
                "bg": spec.background,
            }
        )
    if _should_set_title(captured=captured):
        # set title here to get currently executing command
        pause_call_resume(proc, builtins.__xonsh_shell__.settitle)
    # create command or return if backgrounding.
    if spec.background:
        return
    if captured == "hiddenobject":
        command = HiddenCommandPipeline(
            specs, procs, starttime=starttime, captured=captured
        )
    else:
        command = CommandPipeline(specs, procs, starttime=starttime, captured=captured)
    # now figure out what we should return.
    if captured == "stdout":
        command.end()
        return command.output
    elif captured == "object":
        return command
    elif captured == "hiddenobject":
        command.end()
        return command
    else:
        command.end()
        return


# Traceback (ProcessLookupError)
ls | more
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 17380, in default
run_compiled_code(code, self.ctx, None, 'single')
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 1964, in run_compiled_code
func(code, glb, loc)
File "<xonsh-code>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 16159, in subproc_captured_hiddenobject
return run_subproc(cmds, captured='hiddenobject')
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 16127, in run_subproc
command.end()
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 11116, in end
for _ in self.tee_stdout():
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 11041, in tee_stdout
for line in self.iterraw():
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 10940, in iterraw
wait_for_active_job()
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 3694, in wait_for_active_job
_continue(active_task)
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 3607, in _continue
_send_signal(job, signal.SIGCONT)
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 3542, in _send_signal
os.kill(pid, signal)
ProcessLookupError: [Errno 3] No such process

# Fixed code
def run_subproc(cmds, captured=False):
    """Runs a subprocess, in its many forms. This takes a list of 'commands,'
    which may be a list of command line arguments or a string, representing
    a special connecting character.  For example::

        $ ls | grep wakka

    is represented by the following cmds::

        [['ls'], '|', ['grep', 'wakka']]

    Lastly, the captured argument affects only the last real command.
    """
    specs = cmds_to_specs(cmds, captured=captured)
    captured = specs[-1].captured
    if captured == "hiddenobject":
        command = HiddenCommandPipeline(specs)
    else:
        command = CommandPipeline(specs)
    proc = command.proc
    background = command.spec.background
    if not all(x.is_proxy for x in specs):
        add_job(
            {
                "cmds": cmds,
                "pids": [i.pid for i in command.procs],
                "obj": proc,
                "bg": background,
                "pipeline": command,
                "pgrp": command.term_pgid,
            }
        )
    if _should_set_title(captured=captured):
        # set title here to get currently executing command
        pause_call_resume(proc, builtins.__xonsh_shell__.settitle)
    # create command or return if backgrounding.
    if background:
        return
    # now figure out what we should return.
    if captured == "stdout":
        command.end()
        return command.output
    elif captured == "object":
        return command
    elif captured == "hiddenobject":
        command.end()
        return command
    else:
        command.end()
        return