2015-04-25 8:23 GMT+02:00 Greg Ewing <greg.ew...@canterbury.ac.nz>: > But how is an awaitable supposed to raise StopIteration > if it's implemented by a generator or async def[*] function? > Those things use StopIteration to wrap return values. > > I like the idea of allowing StopIteration to be raised > in an async def function and wrapping it somehow. I'd > add that it could also be unwrapped automatically when > it emerges from 'await', so that code manually invoking > __anext__ can catch StopIteration as usual.
Hum, wrap and then unwrap is not cheap. Exception handling in CPython is known to be slow (it's one of the favorite topic for microbenchmarks ;-)). I would prefer to not make wrapping/unwrapping a feature and instead use different exceptions. Again, I don't understand the problem, so I'm just sure that my remark makes sense. But please be careful of performances. I already saw microbenchmarks on function call vs consuming a generator to justify that asyncio is way too slow and must not be used... See for example the "2. AsyncIO uses appealing, but relatively inefficient Python paradigms" section of the following article: http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databases/ The microbenchmark shows that yield from is 6x as slow as function calls (and function calls are also known to be slow in CPython). (I don't think that it makes sense to compare function calls versus consuming a generator to benchmark asyncio, but other developers have a different opinion of that.) Victor _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com