Subprocess Pipelines (xonsh.procs.pipelines)

Command pipeline tools.

class xonsh.procs.pipelines.CommandPipeline(specs)[source]

Represents a subprocess-mode command pipeline.

Parameters
specslist of SubprocSpec

Process specifications

Attributes
specSubprocSpec

The last specification in specs

procPopen-like

The process in procs

endedbool

Boolean for if the command has stopped executing.

inputstr

A string of the standard input.

outputstr

Non-blocking, lazy access to output

errorsstr

A string of the standard error.

lineslist of str

The output lines

starttimefloats or None

Pipeline start timestamp.

end(tee_output=True)[source]

End the pipeline, return the controlling terminal if needed.

Main things done in self._end().

itercheck()[source]

Iterates through the command lines and throws an error if the returncode is non-zero.

iterraw()[source]

Iterates through the last stdout, and returns the lines exactly as found.

resume(job, tee_output=True)[source]
stream_stderr(lines)[source]

Streams lines to sys.stderr and the errors attribute.

tee_stdout()[source]

Writes the process stdout to the output variable, line-by-line, and yields each line. This may optionally accept lines (in bytes) to iterate over, in which case it does not call iterraw().

property alias

Alias the process used.

property args

Arguments to the process.

attrnames = ('stdin', 'stdout', 'stderr', 'pid', 'returncode', 'args', 'alias', 'stdin_redirect', 'stdout_redirect', 'stderr_redirect', 'timestamps', 'executed_cmd', 'input', 'output', 'errors')
property err

Error messages as a string.

property executed_cmd

The resolve and executed command.

property inp

Creates normalized input string from args.

nonblocking = (<class '_io.BytesIO'>, <class 'xonsh.procs.readers.NonBlockingFDReader'>, <class 'xonsh.procs.readers.ConsoleParallelReader'>)
property out

Output value as a str.

property output

Non-blocking, lazy access to output

property pid

Process identifier.

property raw_err

Errors as raw bytes.

property raw_out

Output as raw bytes.

property returncode

Process return code, waits until command is completed.

property rtn

Alias to return code.

property stderr

Process stderr.

property stderr_postfix

Postfix to print after stderr, as bytes.

property stderr_prefix

Prefix to print in front of stderr, as bytes.

property stderr_redirect

Redirection used for stderr.

property stdin

Process stdin.

property stdin_redirect

Redirection used for stdin.

property stdout

Process stdout.

property stdout_redirect

Redirection used for stdout.

property timestamps

The start and end time stamps.

class xonsh.procs.pipelines.HiddenCommandPipeline(specs)[source]
Parameters
specslist of SubprocSpec

Process specifications

Attributes
specSubprocSpec

The last specification in specs

procPopen-like

The process in procs

endedbool

Boolean for if the command has stopped executing.

inputstr

A string of the standard input.

outputstr

Non-blocking, lazy access to output

errorsstr

A string of the standard error.

lineslist of str

The output lines

starttimefloats or None

Pipeline start timestamp.

class xonsh.procs.pipelines.PrevProcCloser(pipeline)[source]

Previous process closer thread for pipelines whose last command is itself unthreadable. This makes sure that the pipeline is driven forward and does not deadlock.

Parameters
pipelineCommandPipeline

The pipeline whose prev procs we should close.

run()[source]

Runs the closing algorithm.

xonsh.procs.pipelines.pause_call_resume(p, f, *args, **kwargs)[source]

For a process p, this will call a function f with the remaining args and and kwargs. If the process cannot accept signals, the function will be called.

Parameters
pPopen object or similar
fcallable
argsremaining arguments
kwargskeyword arguments
xonsh.procs.pipelines.safe_readable(handle)[source]

Attempts to find if the handle is readable without throwing an error.

xonsh.procs.pipelines.safe_readlines(handle, hint=- 1)[source]

Attempts to read lines without throwing an error.

xonsh.procs.pipelines.update_fg_process_group(pipeline_group, background)[source]