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:
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?
On Thu, Nov 03, 2011 at 12:08:49AM -0700, Matt Starcrest wrote:
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?
In nginx-1.0.9 or nginx-1.1.5 you can try
uwsgi_buffering off;
or
sgi_buffering off;
depending on protocol. In any modern enough nginx version you can use
proxy_buffering off;
There is no way currently to disable buffering of FastCGI servers.
From: Igor S. [email protected]
To: [email protected]
Sent: Thursday, November 3, 2011 12:12 AM
Subject: Re: python wsgi behind nginx: yield not behaving as expected
On Thu, Nov 03, 2011 at 12:08:49AM -0700, Matt Starcrest wrote:
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?
In nginx-1.0.9 or nginx-1.1.5 you can try
uwsgi_buffering off;
or
sgi_buffering off;
depending on protocol. In any modern enough nginx version you can use
proxy_buffering off;
There is no way currently to disable buffering of FastCGI servers.