Package ClusterShell :: Package Worker :: Module Worker :: Class Worker
[hide private]
[frames] | no frames]

Class Worker

source code

Worker is an essential base class for the ClusterShell library. The goal of a worker object is to execute a common work on a single or several targets (abstract notion) in parallel. Concret targets and also the notion of local or distant targets are managed by Worker's subclasses (for example, see the DistantWorker base class).

A configured Worker object is associated to a specific ClusterShell Task, which can be seen as a single-threaded Worker supervisor. Indeed, the work to be done is executed in parallel depending on other Workers and Task's current paramaters, like current fanout value.

ClusterShell is designed to write event-driven applications, and the Worker class is key here as Worker objects are passed as parameter of most event handlers (see the ClusterShell.Event.EventHandler class).

The following public object variables are defined on some events, so you may find them useful in event handlers:

Example of use:

>>> from ClusterShell.Event import EventHandler
>>> class MyOutputHandler(EventHandler):
...     def ev_read(self, worker):
...             node = worker.current_node
...             line = worker.current_msg
...             print "%s: %s" % (node, line)
Instance Methods [hide private]
__init__(self, handler)
source code
_set_task(self, task)
Bind worker to task.
source code
Helper method to check that worker is bound to a task.
source code
Return a list of underlying engine clients.
source code
_on_start(self, key)
Called on command start.
source code
_on_rc(self, key, rc)
Command return code received.
source code
_on_written(self, key, bytes_count, sname)
Notification of bytes written.
source code
Get last read message from event handler.
source code
Get last error message from event handler.
source code
Return whether this worker has aborted due to timeout.
source code
read(self, node=None, sname='stdout')
Read worker stream buffer.
source code
Abort processing any action by this worker.
source code
Flush any messages associated to this worker.
source code
Flush any error messages associated to this worker.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  SNAME_STDIN = 'stdin'
  SNAME_STDOUT = 'stdout'
  SNAME_STDERR = 'stderr'
Instance Variables [hide private]
associated :class:`.EventHandler`
worker's task when scheduled or None
set to True when worker has started
set to node in event handler
set to stdout message in event handler
set to stderr message in event handler
set to return code in event handler
set to stream name in event handler
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, handler)

source code 

Initializer. Should be called from derived classes.

Overrides: object.__init__

_set_task(self, task)

source code 

Bind worker to task. Called by task.schedule().


source code 

Get last read message from event handler. [DEPRECATED] use current_msg


source code 

Get last error message from event handler. [DEPRECATED] use current_errmsg

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

source code 
Read worker stream buffer.

Return stream read buffer of current worker.

    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')