|
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.
Nicolas Lehuen made changes - 01/May/05 07:28 PM
Nicolas Lehuen made changes - 26/Jun/05 07:19 AM
Reopened to fix
Nicolas Lehuen made changes - 10/Dec/05 06:16 PM
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.
Nicolas Lehuen made changes - 10/Dec/05 06:18 PM
Graham Dumpleton made changes - 13/Aug/06 07:49 AM
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Note, I could be talking nonsense here as I have never consciously used generators so making some assumptions about them. :-)