Skip to content Skip to sidebar Skip to footer

In Wsgi, Send Response Without Returning

Is there any way to wrap a WSGI application method such the server will send a response when a particular method is called, rather than when the application method returns a sequen

Solution 1:

WSGI app must return an iterable, one way or another. If you want to send partial responses, turn your application into a generator (or return an iterator):

import wsgiref, wsgiref.simple_server, time

def app(environ, start):
    start('200 OK', [('Content-Type', 'text/plain')])

    yield 'hello '
    time.sleep(10)
    yield 'world'

httpd = wsgiref.simple_server.make_server('localhost', 8999, app)
httpd.serve_forever()

Post a Comment for "In Wsgi, Send Response Without Returning"