'Put an item on the queue, blocking if it is too full.
This is a slightly modified Queue.put method which blocks when the queue
contains more than the threshold.
Args:
item: The item to put - must have a __len__() method.
priority: The priority of this message.
block: If True we block indefinitely.
timeout: Maximum time we spend waiting on the queue (1 sec resolution).
Raises:
Queue.Full: if the queue is full and block is False, or
timeout is exceeded.'

def Put(self, item, priority=rdf_flows.GrrMessage.Priority.MEDIUM_PRIORITY, block=True, timeout=1000):

    if isinstance(item, rdfvalue.RDFValue):
        item = item.SerializeToString()
    if (priority >= rdf_flows.GrrMessage.Priority.HIGH_PRIORITY):
        pass
    elif (not block):
        if (self.total_size >= self.maxsize):
            raise Queue.Full
    else:
        count = 0
        while (self.total_size >= self.maxsize):
            time.sleep(1)
            self.nanny.Heartbeat()
            count += 1
            if (timeout and (count > timeout)):
                raise Queue.Full
    with self.lock:
        self.queue.append((((-1) * priority), item))
        self.total_size += len(item)
