original_docstring: Signals the tool to stop running nicely after an abort.
docstring: Signals the tool to stop running nicely after an abort.
docstring_tokens: Signals the tool to stop running nicely after an abort .
code: def CleanUpAfterAbort(self):
      """Signals the tool to stop running nicely after an abort."""
      if self._single_process_mode and self._debug_mode:
        logging.warning(u'Running in debug mode, set up debugger.')
        pdb.post_mortem()
        return
  
      logging.warning(u'Stopping collector.')
      if self._collector:
        self._collector.SignalEndOfInput()
  
      logging.warning(u'Stopping storage.')
      self._engine.SignalEndOfInputStorageQueue()
  
      # Kill the collection process.
      if self._collection_process:
        logging.warning(u'Terminating the collection process.')
        self._collection_process.terminate()
  
      try:
        logging.warning(u'Waiting for workers to complete.')
        for worker_name, worker_process in self._worker_processes.iteritems():
          pid = worker_process.pid
          logging.warning(u'Waiting for worker: {0:s} [PID {1:d}]'.format(
              worker_name, pid))
          # Let's kill the process, different methods depending on the platform
          # used.
          if sys.platform.startswith('win'):
            import ctypes
            process_terminate = 1
            handle = ctypes.windll.kernel32.OpenProcess(
                process_terminate, False, pid)
            ctypes.windll.kernel32.TerminateProcess(handle, -1)
            ctypes.windll.kernel32.CloseHandle(handle)
          else:
            try:
              os.kill(pid, signal.SIGKILL)
            except OSError as exception:
              logging.error(
                  u'Unable to kill process {0:d} with error: {1:s}'.format(
                      pid, exception))
  
          logging.warning(u'Worker: {0:d} CLOSED'.format(pid))
  
        logging.warning(u'Workers completed.')
        if hasattr(self, 'storage_process'):
          logging.warning(u'Waiting for storage.')
          self._storage_process.join()
          logging.warning(u'Storage ended.')
  
        logging.info(u'Exiting the tool.')
        # Sometimes the main process will be unresponsive.
        if not sys.platform.startswith('win'):
          os.kill(os.getpid(), signal.SIGKILL)
  
      except KeyboardInterrupt:
        logging.warning(u'Terminating all processes.')
        for process in self._worker_processes:
          process.terminate()
  
        logging.warning(u'Worker processes terminated.')
        if hasattr(self, 'storage_process'):
          self._storage_process.terminate()
          logging.warning(u'Storage terminated.')
  
        # Sometimes the main process will be unresponsive.
        if not sys.platform.startswith('win'):
          os.kill(os.getpid(), signal.SIGKILL)
code_tokens: def CleanUpAfterAbort ( self ) : if self . _single_process_mode and self . _debug_mode : logging . warning ( u'Running in debug mode, set up debugger.' ) pdb . post_mortem ( ) return logging . warning ( u'Stopping collector.' ) if self . _collector : self . _collector . SignalEndOfInput ( ) logging . warning ( u'Stopping storage.' ) self . _engine . SignalEndOfInputStorageQueue ( ) if self . _collection_process : logging . warning ( u'Terminating the collection process.' ) self . _collection_process . terminate ( ) try : logging . warning ( u'Waiting for workers to complete.' ) for worker_name , worker_process in self . _worker_processes . iteritems ( ) : pid = worker_process . pid logging . warning ( u'Waiting for worker: {0:s} [PID {1:d}]' . format ( worker_name , pid ) ) if sys . platform . startswith ( 'win' ) : import ctypes process_terminate = 1 handle = ctypes . windll . kernel32 . OpenProcess ( process_terminate , False , pid ) ctypes . windll . kernel32 . TerminateProcess ( handle , - 1 ) ctypes . windll . kernel32 . CloseHandle ( handle ) else : try : os . kill ( pid , signal . SIGKILL ) except OSError as exception : logging . error ( u'Unable to kill process {0:d} with error: {1:s}' . format ( pid , exception ) ) logging . warning ( u'Worker: {0:d} CLOSED' . format ( pid ) ) logging . warning ( u'Workers completed.' ) if hasattr ( self , 'storage_process' ) : logging . warning ( u'Waiting for storage.' ) self . _storage_process . join ( ) logging . warning ( u'Storage ended.' ) logging . info ( u'Exiting the tool.' ) if not sys . platform . startswith ( 'win' ) : os . kill ( os . getpid ( ) , signal . SIGKILL ) except KeyboardInterrupt : logging . warning ( u'Terminating all processes.' ) for process in self . _worker_processes : process . terminate ( ) logging . warning ( u'Worker processes terminated.' ) if hasattr ( self , 'storage_process' ) : self . _storage_process . terminate ( ) logging . warning ( u'Storage terminated.' ) if not sys . platform . startswith ( 'win' ) : os . kill ( os . getpid ( ) , signal . SIGKILL )
short_docstring: Signals the tool to stop running nicely after an abort.
short_docstring_tokens: Signals the tool to stop running nicely after an abort .
comment: """Signals the tool to stop running nicely after an abort."""$SEP$# Kill the collection process.$SEP$# Let's kill the process, different methods depending on the platform$SEP$# used.$SEP$# Sometimes the main process will be unresponsive.$SEP$# Sometimes the main process will be unresponsive.