'Directs further tor controller events to a given function. The function is
expected to take a single argument, which is a
:class:`~stem.response.events.Event` subclass. For instance the following
would print the bytes sent and received by tor over five seconds...
import time
from stem.control import Controller, EventType
def print_bw(event):
print(\'sent: %i, received: %i\' % (event.written, event.read))
with Controller.from_port(port = 9051) as controller:
controller.authenticate()
controller.add_event_listener(print_bw, EventType.BW)
time.sleep(5)
If a new control connection is initialized then this listener will be
reattached.
:param functor listener: function to be called when an event is received
:param stem.control.EventType events: event types to be listened for
:raises: :class:`stem.ProtocolError` if unable to set the events'

def add_event_listener(self, listener, *events):

    with self._event_listeners_lock:
        if self.is_authenticated():
            for event_type in events:
                event_type = stem.response.events.EVENT_TYPE_TO_CLASS.get(event_type)
                if (event_type and (self.get_version() < event_type._VERSION_ADDED)):
                    raise stem.InvalidRequest(552, ('%s    event    requires    Tor    version    %s    or    later' % (event_type, event_type._VERSION_ADDED)))
        for event_type in events:
            self._event_listeners.setdefault(event_type, []).append(listener)
        failed_events = self._attach_listeners()[1]
        failed_events = set(failed_events).intersection(set(events))
        if failed_events:
            raise stem.ProtocolError(('SETEVENTS    rejected    %s' % ',    '.join(failed_events)))
