|
The PEP on generators actually gives an example which if accessible would cause mod_python to blow up if mod_python kept calling it until all values were exhausted. Ie.,
def fib(): a, b = 0, 1 while 1: yield b a, b = b, a+b Thus, safer to make users wrap it in ordinary Python code and collect data themselves and then put it together as required. Nobody prevents anyone from putting an infinite loop in a standard publisher, either. This would cause mod_python to blow up :
dex index(req): while True: req.write('foobar\n') So we don't need to worry about the possibility that some code written by a developer goes into an infinite loop. I really think that the advantages of iterator publication outweight this particular drawback. Reopened to fix
It's a little bit more complicated than expected, because it breaks some RPC / JSON code (which rely on str() being called on tuples or lists)... Plus we should implement chunked encoding when returning content produced by iterators, since we can't set the Content-Length header upfront.
|
||||||||||||||||||||||||||||||||||||||||||||||
Note, I could be talking nonsense here as I have never consciously used generators so making some assumptions about them. :-)