# Buggy code
def _ZeroMQResponder(self, source_queue, socket, terminate_event):
    """Listens for requests and replies to clients.

    Args:
      source_queue: The queue to uses to pull items from.
      socket: The socket to listen to, and send responses to.
      terminate_event: The event that signals that the queue should terminate.

    Raises:
      QueueEmpty: If the queue encountered a timeout trying to push an item.
      zmq.error.ZMQError: If ZeroMQ encounters an error.
    """
    logging.debug("ZeroMQ responder thread started")
    while not terminate_event.isSet():
        try:
            if self._closed:
                # No further items can be added be added to the queue, so we don't
                # need to block.
                item = source_queue.get_nowait()
            else:
                item = source_queue.get(True, timeout=self._buffer_timeout_seconds)
        except Queue.Empty:
            # No item available within timeout, so time to exit.
            self.Close()
            continue

        try:
            self._zmq_socket.send_pyobj(item)
        except zmq.error.Again:
            logging.debug(
                "{0:s} could not push an item within {1:d} seconds.".format(
                    self.name, self.timeout_seconds
                )
            )
            raise errors.QueueEmpty
        except zmq.error.ZMQError as exception:
            if exception.errno == errno.EINTR:
                logging.error("ZMQ syscall interrupted in {0:s}.".format(self.name))
                break
            else:
                raise
    socket.close(self._linger_seconds)


# Traceback (exceptions.AttributeError)
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
File "/usr/lib/python2.7/threading.py", line 763, in run
File "./plaso/engine/zeromq_queue.py", line 651, in _ZeroMQResponder
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'Empty'
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
File "/usr/lib/python2.7/threading.py", line 763, in run
File "./plaso/engine/zeromq_queue.py", line 752, in _ZeroMQResponder
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'Empty'
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
File "/usr/lib/python2.7/threading.py", line 763, in run
File "./plaso/engine/zeromq_queue.py", line 752, in _ZeroMQResponder
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'Empty'
/home/travis/build.sh: line 45:  4478 Segmentation fault      (core dumped) coverage run --source=plaso --omit="*_test*,*__init__*,*test_lib*" ./run_tests.py

# Fixed code
def _ZeroMQResponder(self, source_queue):
    """Listens for requests and replies to clients.

    Args:
      source_queue (Queue.queue):  queue to use to pull items from.

    Raises:
      QueueEmpty: If the queue encountered a timeout trying to push an item.
    """
    logging.debug("{0:s} responder thread started".format(self.name))
    while not self._terminate_event.isSet():
        try:
            if self._closed_event.isSet():
                # No further items can be added be added to the queue, so we don't
                # need to block.
                item = source_queue.get_nowait()
            else:
                item = source_queue.get(True, timeout=self._buffer_timeout_seconds)

        except Queue.Empty:
            logging.debug("{0:s} queue was empty".format(self.name))
            # Signal to any downstream queues that they should abort.
            item = plaso_queue.QueueAbort()
            # Exit after an attempt to inform downstream queues that there are no
            # more events.
            self._terminate_event.set()

        sent_successfully = self._SendItem(self._zmq_socket, item)
        if not sent_successfully:
            logging.error("Queue {0:s} error sending item.")
            break

    logging.info("Queue {0:s} responder exiting.".format(self.name))
    self._zmq_socket.close(self._linger_seconds)