# 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 a timeout occurs when trying to reply to a request.
      zmq.error.ZMQError: If an error occurs in ZeroMQ.
    """
    logging.debug("ZeroMQ responder thread started")
    while not terminate_event.isSet():
        try:
            # We need to receive a request before we send.
            _ = socket.recv()
        except zmq.error.Again:
            logging.debug(
                "{0:s} did not receive a request within the "
                "timeout of {1:d} seconds.".format(self.name, self.timeout_seconds)
            )
            continue
        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

        try:
            if self._closed:
                item = source_queue.get_nowait()
            else:
                item = source_queue.get(True, self._buffer_timeout_seconds)
        except Queue.Empty:
            item = plaso_queue.QueueAbort()

        try:
            self._zmq_socket.send_pyobj(item)
        except zmq.error.Again:
            logging.debug(
                "{0:s} could not reply to a request 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.
    """
    logging.debug("{0:s} responder thread started".format(self.name))

    item = None
    while not self._terminate_event.isSet():
        try:
            if self._closed_event.isSet():
                item = source_queue.get_nowait()
            else:
                item = source_queue.get(True, self._buffer_timeout_seconds)

        except Queue.Empty:
            if self._closed_event.isSet():
                break

            continue

        try:
            # We need to receive a request before we can reply with the item.
            self._ReceiveItemOnActivity(self._zmq_socket)

        except errors.QueueEmpty:
            logging.warn("{0:s} timeout waiting for a request.".format(self.name))
            if self._closed_event.isSet() and self._queue.empty():
                break

            continue

        sent_successfully = self._SendItem(self._zmq_socket, item)
        if not sent_successfully:
            logging.error("Queue {0:s} unable to send item.".format(self.name))
            break

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