Skip to content

EventHandler (class)

thiell edited this page Mar 4, 2012 · 1 revision

EventHandler

The EventHandler class is the base class to derive in order to listen for worker events.

API documentation

$ pydoc ClusterShell.Event.EventHandler

Example of EventHandler

The following code snippet is taken from the clush command. It defines an output handler by implementing 3 callbacks: ev_read(), ev_hup() and ev_timeout():

class OutputHandler(EventHandler):
    def __init__(self, label):
        self._label = label
    def ev_read(self, worker):
        ns, buf = worker.last_read()
        if self._label:
          print "%s: %s" % (ns, buf)
        else:
          print "%s" % buf
    def ev_hup(self, worker):
        ns, rc = worker.last_retcode()
        if rc > 0:
            print "clush: %s: exited with exit code %d" % (ns, rc)
    def ev_timeout(self, worker):
        print "clush: %s: command timeout" % worker.last_node()
Clone this wiki locally