[Web-SIG] Could WSGI handle Asynchronous response?

Phillip J. Eby pje at telecommunity.com
Tue Jul 29 03:16:26 CEST 2008


At 04:23 AM 2/18/2008 -0800, est 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 ?

You are confusing "asynchronous" with "streaming".  WSGI is 
synchronous, but allows streaming and "server push".  Instead of 
returning a sequence, code your application as an iterator that 
yields output chunks.

It is "synchronous" in the sense that if you sleep or do processing 
in between yielded output chunks, you will prevent the server from 
freeing any resources associated with your application, or from doing 
any other work in the current thread.  A properly-designed WSGI 
server should continue to function, as long as all available 
resources aren't consumed...  which in the case of "push" apps could 
easily make your box fall over, regardless of whether WSGI is involved.  :)



More information about the Web-SIG mailing list