code: def perform_exit():
      
      if SPLUNK_DEBUG:
          print('{} -------------------------------'.format(
              rnow()))
          print('{} splunkpub: atexit.register - start'.format(
              rnow()))
      worked = True
      for instance in instances:
          try:
              if SPLUNK_DEBUG:
                  print('{} - shutting down instance={} - start'.format(
                      rnow(),
                      instance))
              instance.shutdown()
              if SPLUNK_DEBUG:
                  print('{} - shutting down instance={} - done'.format(
                      rnow(),
                      instance))
          except Exception as e:
              worked = False
              if SPLUNK_DEBUG:
                  print(
                      '{} - shutting down instance={} '
                      '- hit ex={} during shutdown'.format(
                          rnow(),
                          instance,
                          e))
          # end of try/ex
      if not worked:
          if SPLUNK_DEBUG:
              print('{} Failed exiting'.format(
                  rnow()))
      if SPLUNK_DEBUG:
          print('{} splunkpub: atexit.register - done'.format(
              rnow()))
          print('{} -------------------------------'.format(
              rnow()))
docs: perform_exit
  
      Handling at-the-exit events
      ---------------------------
  
      This will cleanup each worker process which
      could be in the middle of a request/sleep/block
      action. This has been tested on python 3 with
      Celery and single processes.