Pregunta

I'm doing some basic wsgi stuff:

def application(environ, start_response):
    start_response("200", [])
    result = some_long_func()
    return [result]

It happens from time to time that the client disconnects before some_long_func completes and I see the following in my logs:

SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected)...

Is there a way to handle disconnected clients on the application level, i.e. before application() returns?

My server is uwsgi (standalone). No frameworks, just pure python.

¿Fue útil?

Solución

If the iterable returned by the application has a close() method, the server or gateway must call that method upon completion of the current request, whether the request was completed normally, or terminated early due to an error.

So if close() is called before the output iterator has finished, you know client was disconnected.

Otros consejos

No. Within the bounds of the WSGI specification there is no way of handling this. Go search discussions on the mod_wsgi mailing list. One such discussion is:

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top