Class StreamWorker
source code
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.
|
__init__(self,
handler,
key=None,
stderr=False,
timeout=-1,
autoclose=False,
client_class=<class ClusterShell.Worker.Worker.StreamClient at 0x1eba050>)
Initializer. |
source code
|
|
|
set_reader(self,
sname,
sfile,
retain=True,
closefd=True)
Add a readable stream to StreamWorker. |
source code
|
|
|
set_writer(self,
sname,
sfile,
retain=True,
closefd=True)
Set a writable stream to StreamWorker. |
source code
|
|
|
|
|
|
|
_on_msgline(self,
key,
msg,
sname)
Add a message. |
source code
|
|
|
|
|
|
|
read(self,
node=None,
sname=' stdout ' )
Read worker stream buffer. |
source code
|
|
|
|
|
|
Inherited from Worker :
did_timeout ,
flush_buffers ,
flush_errors ,
last_error ,
last_read
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
__init__(self,
handler,
key=None,
stderr=False,
timeout=-1,
autoclose=False,
client_class=<class ClusterShell.Worker.Worker.StreamClient at 0x1eba050>)
(Constructor)
| source code
|
Initializer. Should be called from derived classes.
- Overrides:
object.__init__
- (inherited documentation)
|
set_reader(self,
sname,
sfile,
retain=True,
closefd=True)
| source code
|
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_writer(self,
sname,
sfile,
retain=True,
closefd=True)
| source code
|
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)
|
Source key for this worker is free for use.
Use this method to set the custom source key for this worker.
|
Abort processing any action by this worker.
- Overrides:
Worker.abort
|
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')
- Overrides:
Worker.read
|
Write to worker.
If sname is specified, write to the associated stream, otherwise write
to all writable streams.
|
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.
|