I was able to get this working by making sure nginx notifies upstream about
client disconnections:
server {
...
location / {
uwsgi_pass 127.0.0.1:3032;
include uwsgi_params;
uwsgi_ignore_client_abort off;
proxy_ignore_client_abort off;
}
}
Then in my wsgi code I check inside my loop if the connection_fd descriptor
is still connected:
@cherrypy.expose
def long_polling():
q = queue.Queue()
while True:
try:
fileDescriptor = uwsgi.connection_fd()
if not uwsgi.is_connected(fileDescriptor):
break
yield q.get(timeout=10)
except queue.Empty:
yield "\n" # keep alive
long_polling._cp_config = {'response.stream': True}
- Oddur
On Tue, Feb 5, 2013 at 9:09 PM, Oddur Magnusson
<[email protected]>wrote:
> I have a client that makes a long standing http call, which can take a
> while, using gevent like described here:
> http://projects.unbit.it/uwsgi/wiki/Gevent
>
> But during the request, I need a way to detect if the client has closed
> the connection.
>
> Since I´m using cherry for my dispatching, I want to be able to do
> something like this: http://tools.cherrypy.org/wiki/IsClientConnected
>
> If course when using uwsgi we don´t have the rfile.rfile._sock but I was
> able to find the file descriptor for the uwsgi socket like this
>
> fileDescriptor = int(cherrypy.request.wsgi_environ["wsgi.input"].fileno())
> fileDescriptorState = fcntl.fcntl(fileDescriptor, fcntl.F_GETFD)
>
> but it seems all connections come across the same socket, which I assume
> is the connection from nginx to uwsgi.
>
> Does the nginx uwsgi plugin notify the uwsgi process somehow if a client
> closes the connection before uwsgi manages to finish the request ?
>
> - Oddur
>
>
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi