def get_client(self, conf, get_client_timeout=None):
    """
    Could block while we wait for the pool to become non-empty.

    @param get_client_timeout: how long (in seconds) to wait on the pool
                               to get a client before failing
    """
    # First up, check to see if we have a pool for this endpoint
    if _get_pool_key(conf) not in self.pooldict:
      # Uh-oh, we need to initialise the queue. Take the dict lock.
      # Note that this is 'double-checked locking'.

      # The reason this pattern doesn't work in Java is that the write to the dict
      # may get issued before the construction of the Queue due to new Queue(..) not
      # being atomic. However in Python this becomes CALL_FUNCTION and STORE_FAST,
      # therefore as long as a) the function doesn't get inlined b) Python's bytecode
      # generator doesn't move the write to q before the function completes there's no
      # way for another thread to observe a partially constructed queue.

      # I haven't found a reference for the Python memory model, so I'm leaving this comment
      # here in case unladen-swallow or something breaks this assumption of correctness.

      self.dictlock.acquire()
      try:
        if _get_pool_key(conf) not in self.pooldict:
          q = LifoQueue(self.poolsize)
          for i in xrange(self.poolsize):
            client = construct_superclient(conf)
            client.CID = i
            q.put(client, False)

          # Wait until the queue has been filled with connections before adding
          # it to the pool. This is done last because any exceptions thrown
          # by the client construction could result in there being no
          # connections available in this pool. When `get_client` is called next,
          # it would skip this block because the key has a value, but then it
          # would deadlock later because there are no connections for it to
          # fetch from the pool.
          self.pooldict[_get_pool_key(conf)] = q
      finally:
        self.dictlock.release()

    connection = None

    start_pool_get_time = time.time()
    has_waited_for = 0

    while connection is None:
      if get_client_timeout is not None:
        this_round_timeout = max(min(get_client_timeout - has_waited_for, 1), 0)
      else:
        this_round_timeout = None

      try:
        connection = self.pooldict[_get_pool_key(conf)].get(
          block=True, timeout=this_round_timeout)
      except Queue.Empty:
        has_waited_for = time.time() - start_pool_get_time
        if get_client_timeout is not None and get_client_timeout > has_waited_for:
          raise socket.timeout(
            ("Timed out after %.2f seconds waiting to retrieve a " +
             "%s client from the pool.") % (has_waited_for, conf.service_name))
        logging.warn("Waited %d seconds for a thrift client to %s:%d" %
          (has_waited_for, conf.host, conf.port))

    return connection
dataset/ETHPy150Open cloudera/hue/desktop/core/src/desktop/lib/thrift_util.py/ConnectionPooler.get_client/swapped operands of `>`