PEW's Corner <pewscor...@gmail.com> added the comment:
Regarding the custom async iterator, I don't know if this is the problem you're referring to, but the following code seems to terminate abruptly when running main2() (main1() is fine). This is without your changes, though. import asyncio class CustomAsyncIter: def __init__(self): self.iterator = iter(['A', 'B']) def __aiter__(self): return self async def __anext__(self): try: x = next(self.iterator) except StopIteration: raise StopAsyncIteration from None await asyncio.sleep(1) return x async def main1(): iter1 = CustomAsyncIter() print(await anext(iter1)) # Prints 'A' print(await anext(iter1)) # Prints 'B' print(await anext(iter1)) # Raises StopAsyncIteration async def main2(): iter1 = CustomAsyncIter() print('Before') # Prints 'Before' print(await anext(iter1, 'Z')) # Silently terminates the script!!! print('After') # This never gets executed asyncio.run(main2()) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43751> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com