Python Procedures as Subprocess Commands (xonsh.proc)

Interface for running Python functions as subprocess-mode commands.

Code for several helper methods in the ProcProxy class have been reproduced without modification from subprocess.py in the Python 3.4.2 standard library. The contents of subprocess.py (and, thus, the reproduced methods) are Copyright (c) 2003-2005 by Peter Astrand <astrand@lysator.liu.se> and were licensed to the Python Software foundation under a Contributor Agreement.

class xonsh.proc.CompletedCommand[source]

Represents a completed subprocess-mode command.

Create new instance of _CCTuple(stdin, stdout, stderr, pid, returncode, args, alias, stdin_redirect, stdout_redirect, stderr_redirect, timestamp, executed_cmd)

itercheck()[source]
err

Alias to stderr.

inp

Creates normalized input string from args.

out

Alias to stdout.

rtn

Alias to return code.

class xonsh.proc.ForegroundProcProxy(f, args, stdin=None, stdout=None, stderr=None, universal_newlines=False)[source]

This is process proxy class that runs its alias functions on the same thread that it was called from, which is typically the main thread. This prevents backgrounding the process, but enables debugger and profiler tools (functions) be run on the same thread that they are attempting to debug.

poll()[source]

Check if the function has completed via the returncode or None.

wait(timeout=None)[source]

Runs the function and returns the result. Timeout argument only present for API compatability.

class xonsh.proc.Handle[source]
Close(CloseHandle=None)[source]
Detach()[source]
closed = False
class xonsh.proc.HiddenCompletedCommand[source]

Create new instance of _CCTuple(stdin, stdout, stderr, pid, returncode, args, alias, stdin_redirect, stdout_redirect, stderr_redirect, timestamp, executed_cmd)

class xonsh.proc.ProcProxy(f, args, stdin=None, stdout=None, stderr=None, universal_newlines=False)[source]

Class representing a function to be run as a subprocess-mode command.

Parameters:

f : function

The function to be executed.

args : list

A (possibly empty) list containing the arguments that were given on the command line

stdin : file-like, optional

A file-like object representing stdin (input can be read from here). If stdin is not provided or if it is explicitly set to None, then an instance of io.StringIO representing an empty file is used.

stdout : file-like, optional

A file-like object representing stdout (normal output can be written here). If stdout is not provided or if it is explicitly set to None, then sys.stdout is used.

stderr : file-like, optional

A file-like object representing stderr (error output can be written here). If stderr is not provided or if it is explicitly set to None, then sys.stderr is used.

poll()[source]

Check if the function has completed.

Returns:

None if the function is still executing, True if the function

finished successfully, and False if there was an error.

run()[source]

Set up input/output streams and execute the child function in a new thread. This is part of the threading.Thread interface and should not be called directly.

f = None

The function to be executed. It should be a function of four arguments, described below.

Parameters:

args : list

A (possibly empty) list containing the arguments that were given on the command line

stdin : file-like

A file-like object representing stdin (input can be read from here).

stdout : file-like

A file-like object representing stdout (normal output can be written here).

stderr : file-like

A file-like object representing stderr (error output can be written here).

class xonsh.proc.SimpleForegroundProcProxy(f, args, stdin=None, stdout=None, stderr=None, universal_newlines=False)[source]

Variant of ForegroundProcProxy for simpler functions.

The function passed into the initializer for SimpleForegroundProcProxy should have the form described in the xonsh tutorial. This function is then wrapped to make a new function of the form expected by ForegroundProcProxy.

class xonsh.proc.SimpleProcProxy(f, args, stdin=None, stdout=None, stderr=None, universal_newlines=False)[source]

Variant of ProcProxy for simpler functions.

The function passed into the initializer for SimpleProcProxy should have the form described in the xonsh tutorial. This function is then wrapped to make a new function of the form expected by ProcProxy.

class xonsh.proc.TeePTYProc(args, stdin=None, stdout=None, stderr=None, preexec_fn=None, env=None, universal_newlines=False)[source]

Popen replacement for running commands in teed psuedo-terminal. This allows the capturing AND streaming of stdout and stderr. Availability is Linux-only.

poll()[source]

Polls the spawned process and returns the os.wait code.

wait(timeout=None)[source]

Waits for the spawned process to finish, up to a timeout. Returns the return os.wait code.

pid

The pid of the spawned process.

returncode

The return value of the spawned process or None if the process exited due to a signal.

signal

If the process was terminated by a signal a 2-tuple is returned containing the signal number and a boolean indicating whether a core file was produced. Otherwise None is returned.

stdout

The stdout (and stderr) that was tee’d into a buffer by the psuedo-terminal.

xonsh.proc.foreground(f)[source]

Decorator that specifies that a callable alias should be run only as a foreground process. This is often needed for debuggers and profilers.

xonsh.proc.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:

p : Popen object or similar

f : callable

args : remaining arguments

kwargs : keyword arguments

xonsh.proc.wrap_simple_command(f, args, stdin, stdout, stderr)[source]

Decorator for creating ‘simple’ callable aliases.