Re: Snakelets and WSGI

From: Robert Brewer (fumanchu_at_amor.org)
Date: 10/12/04


Date: Tue, 12 Oct 2004 12:33:32 -0700
To: <irmen@xs4all.nl>, <python-list@python.org>

Alan Kennedy:
>
> > Ah, one of the key questions! And the answer is that, iff you write
> > Snakelets according to the WSGI API, then it should be
> > easily usable on
> > asynchronous architectures. This is achieved through the
> > use of python
> > iterators (e.g. generators), so that application frameworks
> > generate
> > content on demand, when the server/gateway is ready to
> > transmit them.

Irmen de Jong:
> Interesting idea. I haven't thought about generating output this way.
> ...
> Sounds neat, but I think this is a hard thing to do for me.
> Anyway we'll see. First have to read the WSGI doc thoroughly.
> ...
> "using generators". I'm using them
> for other things, but not the generation of output...

Hoepfully you'll find it's simple. You should be able to take
YPage.write() for example, and queue the output into an iterable which
the WSGI server can then iterate over.

The tough part will be that anyone already using Snakelets will have to
rewrite their code if they want to *benefit* from the switch to
iteration; they'll have to change "write()" to "yield value". This
unfortunately means most CGI scripts will have to be generators. This
can be mitigated somewhat by allowing code in, say, overridden
Snakelets.serve() methods to return content as well as yield content (so
not every block of code which calls write() has to be turned into a
generator). Just examine the result of the callable in question; if it
doesn't have a next() attribute, wrap it in iter(list(result)). Kludgy
but it works.

Robert Brewer
MIS
Amor Ministries
fumanchu@amor.org



Relevant Pages

  • Re: ANN: Snakelets 1.35 (simple-to-use web app server with dynamic pages)
    ... >> Have you considered maybe porting Snakelets to WSGI? ... > will be some form of WSGI in a future Snakelets version. ... depending on how the containing WSGI server has been configured. ... There are two halves to the WSGI API: ...
    (comp.lang.python)
  • Re: ANN: Snakelets 1.35 (simple-to-use web app server with dynamic pages)
    ... > I'm happy to say that Snakelets 1.35 is available. ... > This project provides a built-in threaded web server (so you don't ... Have you considered maybe porting Snakelets to WSGI? ... server platforms upon which python web frameworks can and cannot run. ...
    (comp.lang.python)
  • Re: Snakelets and WSGI
    ... but would it be feasible for a server such ... as Snakelets to implement both the WSGI API, ... If I want this, and I understand WSGI correctly, this would ...
    (comp.lang.python)