Пример #1
0
    def PushItem(self, item, block=True):
        """Push an item on to the queue.

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

    Args:
      item (object): item to push on the queue.
      block (Optional[bool]): whether the push should be performed in blocking
          or non-block mode.

    Raises:
      QueueAlreadyClosed: If the queue is closed.
      QueueFull: If the internal buffer was full and it was not possible to
          push the item to the buffer within the timeout.
      RuntimeError: if closed event is missing.
    """
        if not self._closed_event:
            raise RuntimeError('Missing closed event.')

        if self._closed_event.is_set():
            raise errors.QueueAlreadyClosed()

        if not self._zmq_socket:
            self._CreateZMQSocket()

        try:
            if block:
                self._queue.put(item, timeout=self.timeout_seconds)
            else:
                self._queue.put(item, block=False)
        except Queue.Full as exception:
            raise errors.QueueFull(exception)
Пример #2
0
  def PushItem(self, item, block=True):
    """Pushes an item onto the queue.

    Args:
      item (object): item to add.
      block (Optional[bool]): True to block the process when the queue is full.

    Raises:
      QueueFull: if the item could not be pushed the queue because it's full.
    """
    try:
      self._queue.put(item, block=block)
    except Queue.Full as exception:
      raise errors.QueueFull(exception)