class documentation

class StreamWatcher(threading.local): (source)

Known subclasses: invoke.watchers.Responder

View In Hierarchy

A class whose subclasses may act on seen stream data from subprocesses. Subclasses must exhibit the following API; see `Responder` for a concrete example. * ``__init__`` is completely up to each subclass, though as usual, subclasses *of* subclasses should be careful to make use of `super` where appropriate. * `submit` must accept the entire current contents of the stream being watched, as a string, and may optionally return an iterable of strings (or act as a generator iterator, i.e. multiple calls to ``yield <string>``), which will each be written to the subprocess' standard input. .. note:: `StreamWatcher` subclasses exist in part to enable state tracking, such as detecting when a submitted password didn't work & erroring (or prompting a user, or etc). Such bookkeeping isn't easily achievable with simple callback functions. .. note:: `StreamWatcher` subclasses `threading.local` so that its instances can be used to 'watch' both subprocess stdout and stderr in separate threads. .. versionadded:: 1.0

Method submit Act on ``stream`` data, potentially returning responses.
def submit(self, stream): (source)

Act on ``stream`` data, potentially returning responses. :param str stream: All data read on this stream since the beginning of the session. :returns: An iterable of ``str`` (which may be empty). .. versionadded:: 1.0