StreamWorker

class ClusterShell.Worker.Worker.StreamWorker(handler, key=None, stderr=False, timeout=-1, autoclose=False, client_class=<class ClusterShell.Worker.Worker.StreamClient>)

StreamWorker base class [v1.7+]

The StreamWorker class implements a base (but concrete) Worker that can read and write to multiple streams. Unlike most other Workers, it does not execute any external commands by itself. Rather, it should be pre-bound to “streams”, ie. file(s) or file descriptor(s), using the two following methods:

>>> worker.set_reader('stream1', fd1)
>>> worker.set_writer('stream2', fd2)

Like other Workers, the StreamWorker instance should be associated with a Task using task.schedule(worker). When the task engine is ready to process the StreamWorker, all of its streams are being processed together. For that reason, it is not possible to add new readers or writers to a running StreamWorker (ie. task is running and worker is already scheduled).

Configured readers will generate ev_read() events when data is available for reading. So, the following additional public worker variable is available and defines the stream name for the event:

>>> worker.current_sname [ev_read,ev_error]

Please note that ev_error() is called instead of ev_read() when the stream name is ‘stderr’. Indeed, all other stream names use ev_read().

Configured writers will allow the use of the method write(), eg. worker.write(data, ‘stream2’), to write to the stream.

abort()

Abort processing any action by this worker.

read(node=None, sname='stdout')

Read worker stream buffer.

Return stream read buffer of current worker.

Arguments:
node – node name; can also be set to None for simple worker
having worker.key defined (default is None)

sname – stream name (default is ‘stdout’)

set_key(key)

Source key for this worker is free for use.

Use this method to set the custom source key for this worker.

set_reader(sname, sfile, retain=True, closefd=True)

Add a readable stream to StreamWorker.

Arguments:

sname – the name of the stream (string) sfile – the stream file or file descriptor retain – whether the stream retains engine client

(default is True)
closefd – whether to close fd when the stream is closed
(default is True)
set_write_eof(sname=None)

Tell worker to close its writer file descriptor once flushed.

Do not perform writes after this call. Like write(), sname can be optionally specified to target a specific writable stream, otherwise all writable streams are marked as EOF.

set_writer(sname, sfile, retain=True, closefd=True)

Set a writable stream to StreamWorker.

Arguments:

sname – the name of the stream (string) sfile – the stream file or file descriptor retain – whether the stream retains engine client

(default is True)
closefd – whether to close fd when the stream is closed
(default is True)
write(buf, sname=None)

Write to worker.

If sname is specified, write to the associated stream, otherwise write to all writable streams.

class ClusterShell.Worker.Worker.StreamClient(worker, key, stderr, timeout, autoclose)

StreamWorker’s default EngineClient.

StreamClient is the EngineClient subclass used by default by StreamWorker. It handles some generic methods to pass data to the StreamWorker.

set_write_eof(sname=None)

Set EOF flag to writable stream(s).

write(buf, sname=None)

Write to writable stream(s).