Welcome! Log In Create A New Profile

Advanced

python wsgi behind nginx: yield not behaving as expected

Matt Starcrest
November 03, 2011 03:10AM
Hi,
I want to run wsgi python code on a web server behind nginx.  The server needs to respond quickly to an http request, then continue to do some (slow) work after responding.  Python's yield statement seems to fit the bill, as follows:

def application(environ, start_response):
    output = get_response_quickly(environ)

    start_response('200 OK', [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))])

    yield output
    do_slow_work()

If I run this wsgi in a standalone python server (I tried wsgiref, fapws, uwsgi), the caller receives the output immediately (after get_response_quickly()), as desired.  Great.  However, if I run any of these servers behind nginx, the caller doesn't receive a response until *after* do_slow_work() -- thus defeating the purpose.

Is there a way to make this pattern work with nginx?  Or is there a better way in general to respond quickly but continue work, without manually creating python threads / other clumsiness?

Thanks,
Matt_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

python wsgi behind nginx: yield not behaving as expected

Matt Starcrest November 03, 2011 03:10AM

Re: python wsgi behind nginx: yield not behaving as expected

Igor Sysoev November 03, 2011 03:14AM

Re: python wsgi behind nginx: yield not behaving as expected

Matt Starcrest November 03, 2011 03:50AM

Re: python wsgi behind nginx: yield not behaving as expected

Igor Sysoev November 03, 2011 03:52AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 153
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready