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 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:
                      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()