code: def register_handler(self, handler, event_name, args):
          
          if self.started:
              raise IllegalStateError(("Can't register service after polling is"
                                       " started"))
          self.lock.acquire()
          try:
              if event_name in self.handlers:
                  raise DuplicateError('A handler for {} already exists'.format(
                      event_name))
              self.handlers[event_name] = (handler, args)
          finally:
              self.lock.release()
docs: Registers an event handler.
  
          One type of event can only have one event handler associated with it.
  
          Args:
              handler: The event handler function to be registered.
              event_name: Name of the event the handler is for.
              args: User arguments to be passed to the handler when it's called.
  
          Raises:
              IllegalStateError: Raised if attempts to register a handler after
                  the dispatcher starts running.
              DuplicateError: Raised if attempts to register more than one
                  handler for one type of event.