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