Execute a command on the local system in a subprocess. .. note:: When Invoke itself is executed without a controlling terminal (e.g. when ``sys.stdin`` lacks a useful ``fileno``), it's not possible to present a handle on our PTY to local subprocesses. In such situations, `Local` will fallback to behaving as if ``pty=False`` (on the theory that degraded execution is better than none at all) as well as printing a warning to stderr. To disable this behavior, say ``fallback=False``. .. versionadded:: 1.0
Method | __init__ |
Create a new runner with a handle on some `.Context`. |
Method | close |
Close running process' stdin. |
Method | kill |
Forcibly terminate the subprocess. |
Method | read |
Read ``num_bytes`` from the running process' stderr stream. |
Method | read |
Read ``num_bytes`` from the running process' stdout stream. |
Method | returncode |
Return the numeric return/exit code resulting from command execution. |
Method | should |
Should execution attempt to use a pseudo-terminal? |
Method | start |
Initiate execution of ``command`` (via ``shell``, with ``env``). |
Method | stop |
Perform final cleanup, if necessary. |
Instance Variable | parent |
Undocumented |
Instance Variable | pid |
Undocumented |
Instance Variable | status |
Undocumented |
Instance Variable | warned |
Undocumented |
Property | process |
Determine whether our subprocess has terminated. |
Method | _write |
Write ``data`` to running process' stdin. |
Inherited from Runner
:
Method | create |
Create and return a dictionary of IO thread worker objects. |
Method | decode |
Decode some ``data`` bytes, returning Unicode. |
Method | default |
Return a string naming the expected encoding of subprocess streams. |
Method | echo |
Undocumented |
Method | generate |
Return a suitable environment dict based on user input & behavior. |
Method | generate |
Create & return a suitable `Result` instance from the given ``kwargs``. |
Method | handle |
Read process' stderr, storing into a buffer & printing/parsing. |
Method | handle |
Read local stdin, copying into process' stdin as necessary. |
Method | handle |
Read process' stdout, storing into a buffer & printing/parsing. |
Method | make |
Return a `Promise` allowing async control of the rest of lifecycle. |
Method | read |
Read & decode bytes from a local stdin stream. |
Method | read |
Iteratively read & decode bytes from a subprocess' out/err stream. |
Method | respond |
Write to the program's stdin in response to patterns in ``buffer_``. |
Method | run |
Execute ``command``, returning an instance of `Result` once complete. |
Method | send |
Submit an interrupt signal to the running subprocess. |
Method | should |
Determine whether data read from ``input_`` should echo to ``output``. |
Method | start |
Start a timer to `kill` our subprocess after ``timeout`` seconds. |
Method | wait |
Block until the running command appears to have exited. |
Method | write |
Write ``string`` to ``stream``. |
Method | write |
Write encoded ``data`` to the running process' stdin. |
Instance Variable | context |
Undocumented |
Instance Variable | encoding |
Undocumented |
Instance Variable | env |
Undocumented |
Instance Variable | input |
Undocumented |
Instance Variable | opts |
Undocumented |
Instance Variable | program |
Undocumented |
Instance Variable | read |
Undocumented |
Instance Variable | result |
Undocumented |
Instance Variable | stderr |
Undocumented |
Instance Variable | stdout |
Undocumented |
Instance Variable | streams |
Undocumented |
Instance Variable | threads |
Undocumented |
Instance Variable | using |
Undocumented |
Instance Variable | watchers |
Undocumented |
Property | has |
Detect whether any IO threads appear to have terminated unexpectedly. |
Property | timed |
Returns ``True`` if the subprocess stopped because it timed out. |
Method | _collate |
Undocumented |
Method | _finish |
Undocumented |
Method | _handle |
Undocumented |
Method | _run |
Undocumented |
Method | _setup |
Prepare data on ``self`` so we're ready to start running. |
Method | _thread |
Undocumented |
Method | _unify |
Unify `run` kwargs with config options to arrive at local options. |
Instance Variable | _asynchronous |
Undocumented |
Instance Variable | _disowned |
Undocumented |
Instance Variable | _timer |
Undocumented |
invoke.runners.Runner.__init__
Create a new runner with a handle on some `.Context`. :param context: a `.Context` instance, used to transmit default options and provide access to other contextualized information (e.g. a remote-oriented `.Runner` might want a `.Context` subclass holding info about hostnames and ports.) .. note:: The `.Context` given to `.Runner` instances **must** contain default config values for the `.Runner` class in question. At a minimum, this means values for each of the default `.Runner.run` keyword arguments such as ``echo`` and ``warn``. :raises exceptions.ValueError: if not all expected default values are found in ``context``.
invoke.runners.Runner.close_proc_stdin
Close running process' stdin. :returns: ``None``. .. versionadded:: 1.3
invoke.runners.Runner.kill
Forcibly terminate the subprocess. Typically only used by the timeout functionality. This is often a "best-effort" attempt, e.g. remote subprocesses often must settle for simply shutting down the local side of the network connection and hoping the remote end eventually gets the message.
invoke.runners.Runner.read_proc_stderr
Read ``num_bytes`` from the running process' stderr stream. :param int num_bytes: Number of bytes to read at maximum. :returns: A string/bytes object. .. versionadded:: 1.0
invoke.runners.Runner.read_proc_stdout
Read ``num_bytes`` from the running process' stdout stream. :param int num_bytes: Number of bytes to read at maximum. :returns: A string/bytes object. .. versionadded:: 1.0
invoke.runners.Runner.returncode
Return the numeric return/exit code resulting from command execution. :returns: `int` .. versionadded:: 1.0
invoke.runners.Runner.should_use_pty
Should execution attempt to use a pseudo-terminal? :param bool pty: Whether the user explicitly asked for a pty. :param bool fallback: Whether falling back to non-pty execution should be allowed, in situations where ``pty=True`` but a pty could not be allocated. .. versionadded:: 1.0
invoke.runners.Runner.start
Initiate execution of ``command`` (via ``shell``, with ``env``). Typically this means use of a forked subprocess or requesting start of execution on a remote system. In most cases, this method will also set subclass-specific member variables used in other methods such as `wait` and/or `returncode`. :param str command: Command string to execute. :param str shell: Shell to use when executing ``command``. :param dict env: Environment dict used to prep shell environment. .. versionadded:: 1.0
invoke.runners.Runner.stop
Perform final cleanup, if necessary. This method is called within a ``finally`` clause inside the main `run` method. Depending on the subclass, it may be a no-op, or it may do things such as close network connections or open files. :returns: ``None`` .. versionadded:: 1.0
Determine whether our subprocess has terminated. .. note:: The implementation of this method should be nonblocking, as it is used within a query/poll loop. :returns: ``True`` if the subprocess has finished running, ``False`` otherwise. .. versionadded:: 1.0
invoke.runners.Runner._write_proc_stdin
Write ``data`` to running process' stdin. This should never be called directly; it's for subclasses to implement. See `write_proc_stdin` for the public API call. :param data: Already-encoded byte data suitable for writing. :returns: ``None``. .. versionadded:: 1.0