On Nov 25, 1:18 am, Sergey Zaharchenko <[email protected]> wrote: > Hi guys, > > I'm trying to serve a specific stream with web.py (chunked transfer > encoding, yield, etc. - works wonders), but I need to know if the user > has closed the connection so that I could stop generating the stream. > I'm using Apache+mod_wsgi. The webserver logs show an "IOError: failed > to write data" exception occuring in this case, but as far as I > understand I can't catch it (it happens outside the GET handler).
Correct, you can't catch it. This is not specific to mod_wsgi and what would happen with all WSGI servers. > I'm out of ideas. Do you by any chance have any? I would question why you need to catch it. Normally you would only generate more response content when WSGI server calls back into the function doing the yields to get more data. In the case of a closed connection, it would stop doing that anyway. That said, if you need to catch it to stop some external thing which is running, then you should write your WSGI application to return a generator which overrides the close() method so as to be notified when request complete. This will be called for both when all data is sent, and when client connection closed. If you need to behave differently when client connection closed prematurely, then you would need to have an internal progress flag to know. For details on using close() see: http://code.google.com/p/modwsgi/wiki/RegisteringCleanupCode Graham -- You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/webpy?hl=en.
