[Python-Dev] PEP 492 vs. PEP 3152, new round (original) (raw)
Victor Stinner victor.stinner at gmail.com
Sat Apr 25 10:36:22 CEST 2015
- Previous message (by thread): [Python-Dev] PEP 492 vs. PEP 3152, new round
- Next message (by thread): [Python-Dev] PEP 492 vs. PEP 3152, new round
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2015-04-25 8:23 GMT+02:00 Greg Ewing <greg.ewing at 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
- Previous message (by thread): [Python-Dev] PEP 492 vs. PEP 3152, new round
- Next message (by thread): [Python-Dev] PEP 492 vs. PEP 3152, new round
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]