Detecting prematurely closed connection in web.py
Is there a way in Web.py to detect and handle a connection that the user closes while processing a request?
I tried to install a handle handler, but in this case it is not called. It is called only after the request completes successfully:
class handler:
def __init__(self):
pass
def GET(self):
try:
while(True):
pass
except Exception, e:
logger.debug(e)
def unload():
logger.debug('unloaded')
try:
app = web.application(urls, globals())
app.add_processor(web.unloadhook(unload))
application = app.wsgifunc()
except Exception, e:
logger.debug(e)
I open the application in a browser and when it starts spinning in a while loop, I abort the request, but no exception is thrown.
+2
Leonid
source
to share
2 answers
Due to the way web servers and WSGI work, there is generally no reliable way to do this. For an explanation read:
http://groups.google.com/group/modwsgi/browse_frm/thread/8ebd9aca9d317ac9
+1
Graham dumpleton
source
to share
Set a timeout and catch an exception type that specifically covers the closed connection case.
See this on exception handling in Python
+1
Chris ballance
source
to share