Author pewscorner
Recipients Dennis Sweeney, asvetlov, pewscorner, yselivanov
Date 2021-04-07.14:53:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1617807232.75.0.0898396653457.issue43751@roundup.psfhosted.org>
In-reply-to
Content
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())
History
Date User Action Args
2021-04-07 14:53:52pewscornersetrecipients: + pewscorner, asvetlov, yselivanov, Dennis Sweeney
2021-04-07 14:53:52pewscornersetmessageid: <1617807232.75.0.0898396653457.issue43751@roundup.psfhosted.org>
2021-04-07 14:53:52pewscornerlinkissue43751 messages
2021-04-07 14:53:52pewscornercreate