def __wrap(self, func, args, kwargs): async def inner(): try: value = await func(*args, **kwargs) except: exc = to_exception(*sys.exc_info()) else: exc = StopAsyncIteration(value) self.__finished = True await self.__queue_yield.put((None, exc)) return update_wrapper(inner, func)
def inner(*args, **kwargs): def async_yield(*args): return gen._agi_yield(*args) def async_yield_from(*args): return gen._agi_yield_from(*args) ns = uniondict(builtins.__dict__, func.__globals__) ns['async_yield'] = async_yield ns['async_yield_from'] = async_yield_from ns['__builtins__'] = builtins.__dict__ hooked_func = types.FunctionType(func.__code__, ns, func.__name__, func.__defaults__, func.__closure__) hooked_func = update_wrapper(hooked_func, func) gen = asyncgenerator(hooked_func, args, kwargs) return gen