Вопрос

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.

Это было полезно?

Решение

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.

Другие советы

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:

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top