code: def drain_queue(q, close_queue=False):
      """Get all items from a queue until an `Empty` exception is raised.
  
      Args:
          q: `Queue`, the queue to drain.
          close_queue: bool, whether to close the queue, such that no other
          object can be put in. Default is False.
  
      Returns:
          List of all items from the queue.
      """
      items = []
      while True:
          try:
              it = q.get_nowait()
          except queue.Empty:
              break
          items.append(it)
      if close_queue:
          q.close()
      return items
  
imports: import queue
  from functools import wraps
label_desc: Use image node_id 4 for calling a global function with example usage: drain_queue(q, close_queue) and returns: items