btrsync.cmdex

Asynchronous execution of subprocess pipelines.

Functions

create_pipeline(*cmds[, stdin, stdout, stderr])

Asynchronous iterator returning started subprocesses connected together as a pipeline.

ex(*cmds[, stdin, stdout, stderr, timeout, ...])

Execute a series of commands in a pipeline.

ex_out(*cmds[, stdout])

Execute a series of commands in a pipeline, capturing standard output and error.

wait_procs(procs, *[, timeout, abort])

Wait on multiple processes, optionally timing out or aborting on failure.

async btrsync.cmdex.create_pipeline(*cmds, stdin=None, stdout=None, stderr=None)[source]

Asynchronous iterator returning started subprocesses connected together as a pipeline.

Parameters
  • cmds – sequence of btrsync.util.Cmd-like commands that form the pipeline

  • stdin – standard input of the first command in the pipeline; None means inherit from caller. If supplied must be file descriptor or file-like object backed by a file descriptor. If supplied, it is guaranteed to be closed on either success or error.

  • stdout – standard output of the last command in the pipeline; None means inherit from caller If supplied must be file descriptor or file-like object backed by a file descriptor.

  • stderr – standard error of all commands in the pipeline; None means inherit from caller If supplied must be file descriptor or file-like object backed by a file descriptor.

Returns

asyncio.subprocess.Process instances of started processes

async btrsync.cmdex.ex(*cmds, stdin=None, stdout=None, stderr=None, timeout=None, hard_timeout=True, **kwargs)[source]

Execute a series of commands in a pipeline.

Parameters
  • cmds – sequence of btrsync.util.Cmd-like commands that form the pipeline

  • stdin – standard input of the first command in the pipeline; None means inherit from caller

  • stdout – standard output of the last command in the pipeline; None means inherit from caller

  • stderr – standard error of all commands in the pipeline; None means inherit from caller

  • timeout – if not None, time out after this many seconds

  • hard_timeout – if True, kill spawned processes on timeout, otherwise leave them untouched

  • kwargs – additional keyword arguments to be passed to wait_procs()

Returns

a tuple (procs, rets): a list of spawned asyncio.subprocess.Process objects, in the order specified by cmds, and a list of tuples (process, output), in order of completion, of process objects and their captured (stdout, stderr) output, if any

async btrsync.cmdex.ex_out(*cmds, stdout=-1, **kwargs)[source]

Execute a series of commands in a pipeline, capturing standard output and error.

Parameters
  • cmds – sequence of btrsync.util.Cmd-like commands that form the pipeline

  • stdin – standard input of the first command in the pipeline; None means inherit from caller

  • timeout – if not None, time out after this many seconds; remaining running processes are killed on timeout

Returns

a list of tuples (exit_code, output), in the order specified by cmds, of the processes’ exit code and captured (stdout, stderr) output

async btrsync.cmdex.wait_procs(procs, *, timeout=None, abort=False)[source]

Wait on multiple processes, optionally timing out or aborting on failure.

Parameters
  • procs – sequence of processes to wait on

  • timeout – if not None, time out after this many seconds; running processes are left untouched after timeout

  • abort – if True, terminate remaining running processes after an abnormal completion (exit code not 0)

Returns

a list of tuples (process, output), in order of completion, of process objects and their captured (stdout, stderr) output, if any