code: def _sender_main(self):
          
          if not self._http_host:
              self._choose_host()
          last_batch_time = datetime.datetime.utcnow()
  
          while not (self._is_terminated.is_set() and self._event_queue.empty()):
              batch = None
              try:
                  if not self._is_connected.is_set():
                      self._verify_connection()
  
                  batch = self._get_batch(last_batch_time)
                  self._send_batch(batch)
  
              except exceptions.ConnectionFailed:  # Failed to connect to server
                  time.sleep(consts.NO_CONNECTION_SLEEP_TIME)
                  self._is_connected.clear()
  
              except exceptions.EmptyBatch:  # No events in queue, go to sleep
                  time.sleep(consts.EMPTY_BATCH_SLEEP_TIME)
  
              except exceptions.SendFailed as ex:  # Failed to send an event batch
                  self._notify(ex.severity, str(ex))
                  self._is_connected.clear()
  
                  if batch:  # Failed after pulling a batch from the queue
                      self._enqueue_batch(batch)
                      logger.debug(consts.LOG_MSG_ENQUEUED_FAILED_BATCH,
                                   len(batch))
  
              else:  # We sent a batch successfully, server is reachable
                  self._is_connected.set()
  
              finally:  # Advance last batch time
                  last_batch_time = datetime.datetime.utcnow()
docs: Runs on a pysdk_sender_thread and handles sending events to the Alooma
          server. Events are sent every <self._batch_interval> seconds or whenever
          batch size reaches <self._batch_size>