Message390438
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()) |
|
Date |
User |
Action |
Args |
2021-04-07 14:53:52 | pewscorner | set | recipients:
+ pewscorner, asvetlov, yselivanov, Dennis Sweeney |
2021-04-07 14:53:52 | pewscorner | set | messageid: <1617807232.75.0.0898396653457.issue43751@roundup.psfhosted.org> |
2021-04-07 14:53:52 | pewscorner | link | issue43751 messages |
2021-04-07 14:53:52 | pewscorner | create | |
|