Could WSGI handle Asynchronous response?

est electronixtar at gmail.com
Mon Feb 18 15:48:26 CET 2008


On Feb 18, 10:35 pm, Jean-Paul Calderone <exar... at divmod.com> wrote:
> On Mon, 18 Feb 2008 05:27:41 -0800 (PST), est <electronix... at gmail.com> wrote:
> >On Feb 18, 7:05 pm, est <electronix... at gmail.com> wrote:
> >> I am writing a small 'comet'-like app using flup, something like this:
>
> >> def myapp(environ, start_response):
> >>     start_response('200 OK', [('Content-Type', 'text/plain')])
> >>     return ['Flup works!\n']        <-------------Could this be part
> >> of response output? Could I time.sleep() for a while then write other
> >> outputs?
>
> >> if __name__ == '__main__':
> >>     from flup.server.fcgi import WSGIServer
> >>     WSGIServer(myapp, multiplexed=True, bindAddress=('0.0.0.0',
> >> 8888)).run()
>
> >> So is WSGI really synchronous? How can I handle asynchronous outputs
> >> with flup/WSGI ?
>
> >figured out myself :blush: :blush:
>
> >def demo_app(environ,start_response):
> >    from StringIO import StringIO
> >    stdout = StringIO()
> >    print >>stdout, "Hello world!"
> >    print >>stdout
> >    h = environ.items(); h.sort()
> >    for k,v in h:
> >        print >>stdout, k,'=',`v`
> >    k=start_response("200 OK", [('Content-Type','text/plain')])
> >    for x in range(1, 100):
> >        k(str(x))
> >        time.sleep(1)
> >    return [stdout.getvalue()]
>
> You can do this, but notice that you use up a thread (or a process) for
> each client by doing so.  This means you'll be limited to a fairly small
> number of concurrent clients.
>
> Jean-Paul- Hide quoted text -
>
> - Show quoted text -

So, is there any solution that handles this nicely? Or, more
specificly, is there any solution that is more 'comet'-like, let's say
'socket'-like than WSGI which could almost do full-dulex HTTP
communications, and ready-to-use server & client event-based code
library?



More information about the Python-list mailing list