code: def poll_events(self):
          
          while self.started:
              event_obj = None
              event_name = None
              try:
                  event_obj = self._sl4a.eventWait(50000)
              except:
                  if self.started:
                      print("Exception happened during polling.")
                      print(traceback.format_exc())
                      raise
              if not event_obj:
                  continue
              elif 'name' not in event_obj:
                  print("Received Malformed event {}".format(event_obj))
                  continue
              else:
                  event_name = event_obj['name']
              # if handler registered, process event
              if event_name in self.handlers:
                  self.handle_subscribed_event(event_obj, event_name)
              if event_name == "EventDispatcherShutdown":
                  self._sl4a.closeSl4aSession()
                  break
              else:
                  self.lock.acquire()
                  if event_name in self.event_dict:  # otherwise, cache event
                      self.event_dict[event_name].put(event_obj)
                  else:
                      q = queue.Queue()
                      q.put(event_obj)
                      self.event_dict[event_name] = q
                  self.lock.release()
docs: Continuously polls all types of events from sl4a.
  
          Events are sorted by name and store in separate queues.
          If there are registered handlers, the handlers will be called with
          corresponding event immediately upon event discovery, and the event
          won't be stored. If exceptions occur, stop the dispatcher and return