[Web-SIG] yield considered harmful (was: x-wsgiorg.flush)
Phillip J. Eby
pje at telecommunity.com
Fri Oct 5 19:02:04 CEST 2007
At 11:57 AM 10/5/2007 -0300, Rob De Almeida wrote:
>Phillip J. Eby wrote:
>>I mean that you can't write a WSGI 2.0 application using a single
>>generator function, because it has to return a tuple, not an
>>iterator. This will discourage people from thinking "yield" is a
>>good way to build up their output, instead of using a StringIO or
>>''.join() on a list of strings.
>Could you explain why using 'yield' is not recommended? Just
>curious, because I use it all the time.
Because you're slowing down your application's throughput. The only
reasons to yield multiple strings is when you are either:
1. Sending a file that's larger than you want to load into memory, or
2. You're doing "server push" and need to do some processing between payloads.
More information about the Web-SIG