import queue


def DrainQueue(q):
  """Returns as many elements as can be obtained from a queue without blocking.

  (This may be no elements at all.)
  """
  ret = []
  while True:
    try:
      ret.append(q.get_nowait())
    except queue.Empty:
      break
  return ret