# Buggy code
def _StopAnalysisProcesses(self, abort=False):
    """Stops the analysis processes.

    Args:
      abort (bool): True to indicated the stop is issued on abort.
    """
    logging.debug("Stopping analysis processes.")
    self._StopMonitoringProcesses()

    # Note that multiprocessing.Queue is very sensitive regarding
    # blocking on either a get or a put. So we try to prevent using
    # any blocking behavior.

    if abort:
        # Signal all the processes to abort.
        self._AbortTerminate()

    if not self._use_zeromq:
        logging.debug("Emptying queues.")
        for event_queue in self._event_queues:
            event_queue.Empty()

    # Wake the processes to make sure that they are not blocking
    # waiting for the queue new items.
    for event_queue in self._event_queues:
        event_queue.PushItem(plaso_queue.QueueAbort(), block=False)

    # Try waiting for the processes to exit normally.
    self._AbortJoin(timeout=self._PROCESS_JOIN_TIMEOUT)
    for event_queue in self._event_queues:
        event_queue.Close(abort=abort)

    if abort:
        # Kill any remaining processes.
        self._AbortKill()
    else:
        # Check if the processes are still alive and terminate them if necessary.
        self._AbortTerminate()
        self._AbortJoin(timeout=self._PROCESS_JOIN_TIMEOUT)

        for event_queue in self._event_queues:
            event_queue.Close(abort=True)


# Traceback (KeyError)
[ERROR] (nsrlsvr   ) PID:XXXXX <analysis_process> <dfvfs.path.os_path_spec.OSPathSpec object at 0xXXXXXXXXXXXX>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/plaso/multi_processing/analysis_process.py", line 138, in _Main
self._analysis_mediator.ProduceAnalysisReport(self._analysis_plugin)
File "/usr/lib/python2.7/dist-packages/plaso/analysis/mediator.py", line 95, in ProduceAnalysisReport
analysis_report = plugin.CompileReport(self)
File "/usr/lib/python2.7/dist-packages/plaso/analysis/interface.py", line 280, in CompileReport
hash_analysis)
File "/usr/lib/python2.7/dist-packages/plaso/analysis/interface.py", line 187, in _HandleHashAnalysis
event_uuids = self._event_uuids_by_pathspec.pop(pathspec)
KeyError: <dfvfs.path.os_path_spec.OSPathSpec object at 0xXXXXXXXXXXXX>

# Fixed code
def _StopAnalysisProcesses(self, abort=False):
    """Stops the analysis processes.

    Args:
      abort (bool): True to indicated the stop is issued on abort.
    """
    logging.debug("Stopping analysis processes.")
    self._StopMonitoringProcesses()

    # Note that multiprocessing.Queue is very sensitive regarding
    # blocking on either a get or a put. So we try to prevent using
    # any blocking behavior.

    if abort:
        # Signal all the processes to abort.
        self._AbortTerminate()

    if not self._use_zeromq:
        logging.debug("Emptying queues.")
        for event_queue in self._event_queues.values():
            event_queue.Empty()

    # Wake the processes to make sure that they are not blocking
    # waiting for the queue new items.
    for event_queue in self._event_queues.values():
        event_queue.PushItem(plaso_queue.QueueAbort(), block=False)

    # Try waiting for the processes to exit normally.
    self._AbortJoin(timeout=self._PROCESS_JOIN_TIMEOUT)
    for event_queue in self._event_queues.values():
        event_queue.Close(abort=abort)

    if abort:
        # Kill any remaining processes.
        self._AbortKill()
    else:
        # Check if the processes are still alive and terminate them if necessary.
        self._AbortTerminate()
        self._AbortJoin(timeout=self._PROCESS_JOIN_TIMEOUT)

        for event_queue in self._event_queues.values():
            event_queue.Close(abort=True)