# Buggy code
def PopItem(self):
    """Pops an item off the queue.

    If no ZeroMQ socket has been created, one will be created the first
    time this method is called.

    Returns:
      The item retrieved from the queue, as a deserialized Python object.

    Raises:
      KeyboardInterrupt: If the process is sent a KeyboardInterrupt while
                         popping an item.
      QueueEmpty: If the queue is empty, and no item could be popped within the
                  queue timeout.
      zmq.error.ZMQError: If an error occurs in ZeroMQ.

    """
    logging.debug("Pop on {0:s} queue, port {1:d}".format(self.name, self.port))
    if not self._zmq_socket:
        self._CreateZMQSocket()
    try:
        self._zmq_socket.send_pyobj(None)
        return self._zmq_socket.recv_pyobj()
    except zmq.error.Again:
        raise errors.QueueEmpty
    except zmq.error.ZMQError as exception:
        if exception.errno == errno.EINTR:
            logging.error(
                "ZMQ syscall interrupted in {0:s}. Queue aborting.".format(self.name)
            )
            return plaso_queue.QueueAbort()
        else:
            raise
    except KeyboardInterrupt:
        self.Close(abort=True)
        raise


# 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 PopItem(self):
    """Pops an item off the queue.

    If no ZeroMQ socket has been created, one will be created the first
    time this method is called.

    Returns:
      object: item from the queue.

    Raises:
      KeyboardInterrupt: If the process is sent a KeyboardInterrupt while
          popping an item.
      QueueEmpty: If the queue is empty, and no item could be popped within the
          queue timeout.
      zmq.error.ZMQError: If an error occurs in ZeroMQ.
    """
    logging.debug("Pop on {0:s} queue, port {1:d}".format(self.name, self.port))

    if not self._zmq_socket:
        self._CreateZMQSocket()

    last_retry_time = time.time() + self.timeout_seconds
    while not self._terminate_event.isSet():
        try:
            self._zmq_socket.send_pyobj(None)
            break

        except zmq.error.Again:
            # The existing socket is now out of sync, so we need to open a new one.
            self._CreateZMQSocket()
            if time.time() > last_retry_time:
                logging.warn("{0:s} timeout requesting item".format(self.name))
                raise errors.QueueEmpty

            continue

    while not self._terminate_event.isSet():
        try:
            return self._ReceiveItemOnActivity(self._zmq_socket)
        except errors.QueueEmpty:
            continue

        except KeyboardInterrupt:
            self.Close(abort=True)
            raise