[issue26221] asynco run_in_executor swallows StopIteration

2016-01-31 Thread Ian Kelly
Ian Kelly added the comment: The place I'd expect to find it is in https://docs.python.org/3/library/asyncio-task.html#coroutines, in the list of "things a coroutine can do". The first two bullets in the list say that any exceptions raised will be propagated. Maybe there should be a note

[issue26221] asynco run_in_executor swallows StopIteration

2016-01-27 Thread Guido van Rossum
Guido van Rossum added the comment: Can you suggest a sentence to insert into the docs and a place where to insert it? (As you can imagine I'm pretty blind for such issues myself.) -- ___ Python tracker

[issue26221] asynco run_in_executor swallows StopIteration

2016-01-27 Thread Ian Kelly
New submission from Ian Kelly: 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 =

[issue26221] asynco run_in_executor swallows StopIteration

2016-01-27 Thread STINNER Victor
Changes by STINNER Victor : -- nosy: -haypo ___ Python tracker ___ ___

[issue26221] asynco run_in_executor swallows StopIteration

2016-01-27 Thread Guido van Rossum
Guido van Rossum added the comment: What are you trying to do here? Can you post a simple example of an iterator that you would like to use with this? Without that it just raises my hackles -- it seems totally wrong to run an iterator in another thread. (Or is the iterator really a

[issue26221] asynco run_in_executor swallows StopIteration

2016-01-27 Thread Ian Kelly
Ian Kelly added the comment: The idea is that the wrapped iterator is something potentially blocking, like a database cursor that doesn't natively support asyncio. Usage would be something like this: async def get_data(): cursor.execute('select * from stuff') async for row in

[issue26221] asynco run_in_executor swallows StopIteration

2016-01-27 Thread Guido van Rossum
Guido van Rossum added the comment: StopIteration has a special meaning. Don't use set_exception() with it. You probably need a more roundabout way to do this. Instead of submitting each __next__() call to the executor separately, you should submit something to the executor that pulls the

[issue26221] asynco run_in_executor swallows StopIteration

2016-01-27 Thread Ian Kelly
Ian Kelly added the comment: Fair enough. I think there should be some documentation though to the effect that coroutines aren't robust to passing StopIteration across coroutine boundaries. It's particularly surprising with PEP-492 coroutines, since those aren't even iterators and intuitively