This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ikelly
Recipients gvanrossum, ikelly, vstinner, yselivanov
Date 2016-01-27.17:25:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I was playing around with this class for adapting regular iterators to async iterators using BaseEventLoop.run_in_executor:

import asyncio

class AsyncIteratorWrapper:

    def __init__(self, iterable, loop=None, executor=None):
        self._iterator = iter(iterable)
        self._loop = loop or asyncio.get_event_loop()
        self._executor = executor

    async def __aiter__(self):
        return self

    async def __anext__(self):
            return await self._loop.run_in_executor(
                    self._executor, next, self._iterator)
        except StopIteration:
            raise StopAsyncIteration

Unfortunately this fails because when next raises StopIteration, run_in_executor swallows the exception and just returns None back to the coroutine, resulting in an infinite iterator of Nones.
Date User Action Args
2016-01-27 17:25:33ikellysetrecipients: + ikelly, gvanrossum, vstinner, yselivanov
2016-01-27 17:25:33ikellysetmessageid: <>
2016-01-27 17:25:33ikellylinkissue26221 messages
2016-01-27 17:25:33ikellycreate