[Web-SIG] wsgi and generators (was Re: WSGI and start_response)

Dirkjan Ochtman dirkjan at ochtman.nl
Sat Apr 10 15:45:26 CEST 2010


On Sat, Apr 10, 2010 at 15:04, Chris Dent <chris.dent at gmail.com> wrote:
> On Thu, 8 Apr 2010, P.J. Eby wrote:
>> This is also a good time for people to learn that generators are usually a
>> *very bad* way to write WSGI apps - yielding is for server push or sending
>> blocks of large files, not tiny strings.  In general, if you're yielding
>> more than one block, you're almost certainly doing WSGI wrong.  The typical
>> HTML, XML, or JSON output that's 99% of a webapp's requests should be
>> transmitted as a single string, rather than as a series of snippets.

While I agree that it doesn't make sense to yield small strings, it
seems to make perfect sense to chunk up larger buffers (e.g. starting
at several kilobytes). This is something we do when transmitting
Mercurial changesets, for example.

Cheers,

Dirkjan


More information about the Web-SIG mailing list