xonsh.procs.proxies#

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.procs.proxies.FileThreadDispatcher(default=None)[source]#

Dispatches to different file handles depending on the current thread. Useful if you want file operation to go to different places for different threads.

Parameters
defaultfile-like or None, optional

The file handle to write to if a thread cannot be found in the registry. If None, a new in-memory instance.

Attributes
registrydict

Maps thread idents to file handles.

close()[source]#

Closes the current thread’s handle.

deregister()[source]#

Removes the current thread from the registry.

detach()[source]#

Detaches the buffer for the current thread.

fileno()[source]#

Returns the file descriptor for the current thread.

flush()[source]#

Flushes the file descriptor for the current thread.

isatty()[source]#

Returns if the file descriptor for the current thread is a tty.

read(size=None)[source]#

Reads from the handle for the current thread.

readable()[source]#

Returns if file descriptor for the current thread is readable.

readline(size=- 1)[source]#

Reads a line from the handle for the current thread.

readlines(hint=- 1)[source]#

Reads lines from the handle for the current thread.

register(handle)[source]#

Registers a file handle for the current thread. Returns self so that this method can be used in a with-statement.

seek(offset, whence=0)[source]#

Seeks the current file.

seekable()[source]#

Returns if file descriptor for the current thread is seekable.

tell()[source]#

Reports the current position in the handle for the current thread.

truncate(size=None)[source]#

Truncates the file for for the current thread.

writable(size=None)[source]#

Returns if file descriptor for the current thread is writable.

write(s)[source]#

Writes to this thread’s handle. This also flushes, just to be extra sure the string was written.

writelines()[source]#

Writes lines for the file descriptor for the current thread.

property available#

True if the thread is available in the registry.

property buffer#

Gets the buffer for this thread’s handle.

property closed#

Is the thread’s handle closed.

property encoding#

Gets the encoding for this thread’s handle.

property errors#

Gets the errors for this thread’s handle.

property handle#

Gets the current handle for the thread.

property line_buffering#

Gets if line buffering for this thread’s handle enabled.

property newlines#

Gets the newlines for this thread’s handle.

class xonsh.procs.proxies.Handle[source]#
Close(CloseHandle=None)[source]#
Detach()[source]#
as_integer_ratio(/)#

Return integer ratio.

Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_length(/)#

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()#

Returns self, the complex conjugate of any int.

from_bytes(/, bytes, byteorder, *, signed=False)#

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value.

signed

Indicates whether two’s complement is used to represent the integer.

to_bytes(/, length, byteorder, *, signed=False)#

Return an array of bytes representing an integer.

length

Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value.

signed

Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.

closed = False#
denominator#

the denominator of a rational number in lowest terms

imag#

the imaginary part of a complex number

numerator#

the numerator of a rational number in lowest terms

real#

the real part of a complex number

class xonsh.procs.proxies.ProcProxy(f, args, stdin=None, stdout=None, stderr=None, universal_newlines=False, close_fds=False, env=None)[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 the process from running on a background thread, 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 compatibility.

class xonsh.procs.proxies.ProcProxyThread(f, args, stdin=None, stdout=None, stderr=None, universal_newlines=False, close_fds=False, env=None)[source]#

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

Parameters
ffunction

The function to be executed.

argslist

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

stdinfile-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.

stdoutfile-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.

stderrfile-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.

universal_newlinesbool, optional

Whether or not to use universal newlines.

close_fdsbool, optional

Whether or not to close file descriptors. This is here for Popen compatability and currently does nothing.

envMapping, optional

Environment mapping.

getName()#
isDaemon()#
is_alive()#

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.

join(timeout=None)#

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

poll()[source]#

Check if the function has completed.

Returns
None if the function is still executing, and the returncode otherwise
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.

setDaemon(daemonic)#
setName(name)#
start()#

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

wait(timeout=None)[source]#

Waits for the process to finish and returns the return code.

property daemon#

A boolean value indicating whether this thread is a daemon thread.

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when only daemon threads are left.

property ident#

Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.

property name#

A string used for identification purposes only.

It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.

property native_id#

Native integral thread ID of this thread, or None if it has not been started.

This is a non-negative integer. See the get_native_id() function. This represents the Thread ID as reported by the kernel.

xonsh.procs.proxies.parse_proxy_return(r, stdout, stderr)[source]#

Proxies may return a variety of outputs. This handles them generally.

Parameters
rtuple, str, int, or None

Return from proxy function

stdoutfile-like

Current stdout stream

stdoutfile-like

Current stderr stream

Returns
cmd_resultint

The return code of the proxy

xonsh.procs.proxies.partial_proxy(f)[source]#

Dispatches the appropriate proxy function based on the number of args.

xonsh.procs.proxies.proxy_five(f, args, stdin, stdout, stderr, spec, stack)[source]#

Calls a proxy function which takes four parameter: args, stdin, stdout, stderr, and spec.

xonsh.procs.proxies.proxy_four(f, args, stdin, stdout, stderr, spec, stack)[source]#

Calls a proxy function which takes four parameter: args, stdin, stdout, and stderr.

xonsh.procs.proxies.proxy_one(f, args, stdin, stdout, stderr, spec, stack)[source]#

Calls a proxy function which takes one parameter: args

xonsh.procs.proxies.proxy_three(f, args, stdin, stdout, stderr, spec, stack)[source]#

Calls a proxy function which takes three parameter: args, stdin, stdout.

xonsh.procs.proxies.proxy_two(f, args, stdin, stdout, stderr, spec, stack)[source]#

Calls a proxy function which takes two parameter: args and stdin.

xonsh.procs.proxies.proxy_zero(f, args, stdin, stdout, stderr, spec, stack)[source]#

Calls a proxy function which takes no parameters.

xonsh.procs.proxies.safe_flush(handle)[source]#

Attempts to safely flush a file handle, returns success bool.

xonsh.procs.proxies.still_writable(fd)[source]#

Determines whether a file descriptor is still writable by trying to write an empty string and seeing if it fails.