shutdown

def shutdown(
            self):
        """shutdown"""
        self.debug_log('shutdown - start')

        # Only initiate shutdown once
        if not self.shutdown_now:
            self.debug_log('shutdown - still shutting down')
            # Cancels the scheduled Timer, allows exit immediately
            if self.timer:
                self.timer.cancel()
                self.timer = None
            return
        else:
            self.debug_log('shutdown - start - setting instance shutdown')
            self.shutdown_now = True
            self.shutdown_event.set()
        # if/else already shutting down

        # Cancels the scheduled Timer, allows exit immediately
        self.timer.cancel()
        self.timer = None

        self.debug_log(
            'shutdown - publishing remaining logs')

        if self.sleep_interval > 0:
            try:
                self.build_payload_from_queued_messages(
                    use_queue=self.queue,
                    shutdown_event=self.shutdown_event,
                    triggered_by_shutdown=True)
            except Exception as e:
                self.write_log((
                    'shutdown - failed to build a payload for remaining '
                    'messages in queue Exception shutting down '
                    'with ex={}').format(
                    e))

            self.debug_log(
                'publishing remaining logs')

            # Send the remaining items in the queue
            self.publish_to_splunk()
        # end of try to publish remaining messages in the queue
        # during shutdown

        self.debug_log('shutdown - done')