docs: def mainLoop(self):
          """This main loop yields to gevent until the end, handling function calls along the way."""
          self.greenlet = gevent.getcurrent()
          callqueue = self._callqueue
          seconds = self.seconds
          try:
              while 1:
                  self._wait = 0
                  now = seconds()
                  if len(callqueue) > 0:
                      self._wake = delay = callqueue[0].time
                      delay -= now
                  else:
                      self._wake = now + 300
                      delay = 300
                  try:
                      self._wait = 1
                      try:
                          self._threadCallNotification.get(timeout=delay if delay > 0 else 0)
                      except Empty:
                          pass
                      else:
                          raise Reschedule
                      self._wait = 0
                  except Reschedule:
                      if self.threadCallQueue:
                          total = len(self.threadCallQueue)
                          count = 0
                          for fn, args, kwargs in self.threadCallQueue:
                              try:
                                  fn(*args, **kwargs)
                              except:
                                  log.err()
                              count += 1
                              if count == total:
                                  break
                          del self.threadCallQueue[:count]
                          if self.threadCallQueue:
                              self.wakeUp()
                      continue
                  now = seconds()
                  while 1:
                      try:
                          c = callqueue[0]
                      except IndexError:
                          break
                      if c.time <= now:
                          del callqueue[0]
                          try:
                              c()
                          except GreenletExit:
                              raise
                          except:
                              log.msg('Unexpected error in main loop.')
                              log.err()
                      else:
                          break
          except (GreenletExit, KeyboardInterrupt):
              pass
          log.msg('Main loop terminated.')
          self.fireSystemEvent('shutdown')