human
Complete this python program:
def generate_in_background(generator, num_cached=10):
assistant
#Here is the Python program you requested.

    """Runs a generator in a background thread, caching up to `num_cached` items.
    """
    import Queue
    queue = Queue.Queue(maxsize=num_cached)
    sentinel = object()
    def producer():
        for item in generator:
            queue.put(item)
        queue.put(sentinel)
    import threading
    thread = threading.Thread(target=producer)
    thread.daemon = True
    thread.start()
    item = queue.get()
    while (item is not sentinel):
        (yield item)
        item = queue.get()