In WSGI, send response without returning

∥☆過路亽.° 提交于 2019-12-24 04:30:12

问题


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 sequence?

Basically, I'd like to have the equivalent of a finish_response(responseValue) method.


回答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()


来源:https://stackoverflow.com/questions/8041001/in-wsgi-send-response-without-returning

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!