human
Complete this python program:
def engine(func):
assistant
#Here is the Python code you requested.

    """Callback-oriented decorator for asynchronous generators.
    This is an older interface; for new code that does not need to be
    compatible with versions of Tornado older than 3.0 the
    `coroutine` decorator is recommended instead.
    This decorator is similar to `coroutine`, except it does not
    return a `.Future` and the ``callback`` argument is not treated
    specially.
    In most cases, functions decorated with `engine` should take
    a ``callback`` argument and invoke it with their result when
    they are finished.  One notable exception is the
    `~tornado.web.RequestHandler` :ref:`HTTP verb methods <verbs>`,
    which use ``self.finish()`` in place of a callback argument.
    """
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        runner = None
        def handle_exception(typ, value, tb):
            if (runner is not None):
                return runner.handle_exception(typ, value, tb)
            return False
        with ExceptionStackContext(handle_exception) as deactivate:
            try:
                result = func(*args, **kwargs)
            except (Return, StopIteration) as e:
                result = getattr(e, 'value', None)
            else:
                if isinstance(result, types.GeneratorType):
                    def final_callback(value):
                        if (value is not None):
                            raise ReturnValueIgnoredError(('@gen.engine    functions    cannot    return    values:    %r' % (value,)))
                        assert (value is None)
                        deactivate()
                    runner = Runner(result, final_callback)
                    runner.run()
                    return
            if (result is not None):
                raise ReturnValueIgnoredError(('@gen.engine    functions    cannot    return    values:    %r' % (result,)))
            deactivate()
    return wrapper