Subprocess Python Proxies (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.
-
register
(handle)[source]¶ Registers a file handle for the current thread. Returns self so that this method can be used in a with-statement.
-
write
(s)[source]¶ Writes to this thread’s handle. This also flushes, just to be extra sure the string was written.
-
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.
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.
-
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.
-
poll
()[source]¶ Check if the function has completed.
- Returns
- None if the function is still executing, and the returncode otherwise
-
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.