문제

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