+def queue_with(items):
+ """Return a thread-safe iterator that yields the given items.
+
+ +items+ can be given as an array or an iterator. If an iterator is
+ given, it will be consumed to fill the queue before queue_with()
+ returns.
+ """
+ queue = Queue.Queue()
+ for val in items:
+ queue.put(val)
+ return lambda *args, **kwargs: queue.get(block=False)
+