human
Complete this python program:
def iterateInReactor(i):
assistant
#Here is the Python program you requested.

    """Consume an interator at most a single iteration per reactor iteration.
    If the iterator produces a Deferred, the next iteration will not occur
    until the Deferred fires, otherwise the next iteration will be taken
    in the next reactor iteration.
    @rtype: C{Deferred}
    @return: A deferred which fires (with None) when the iterator is
    exhausted or whose errback is called if there is an exception.
    """
    from twisted.internet import reactor
    d = defer.Deferred()
    def go(last):
        try:
            r = next(i)
        except StopIteration:
            d.callback(last)
        except:
            d.errback()
        else:
            if isinstance(r, defer.Deferred):
                r.addCallback(go)
            else:
                reactor.callLater(0, go, r)
    go(None)
    return d