Message259036
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):
try:
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:33 | ikelly | set | recipients:
+ ikelly, gvanrossum, vstinner, yselivanov |
2016-01-27 17:25:33 | ikelly | set | messageid: <1453915533.75.0.0706458699162.issue26221@psf.upfronthosting.co.za> |
2016-01-27 17:25:33 | ikelly | link | issue26221 messages |
2016-01-27 17:25:33 | ikelly | create | |
|