+import sys, traceback
+import env
+
__all__ = ["restart"]
class restart(Exception):
if hasattr(self.bk, "close"):
self.bk.close()
+def defaulterror(req, excinfo):
+ import resp
+ traceback.print_exception(*excinfo)
+ raise resp.httperror(500)
+
+def wraphandler(handler, excinfo):
+ def wrapped(req):
+ return handler(req, excinfo)
+ return wrapped
+
+errorhandler = env.var(defaulterror)
+
def handle(req, startreq, handler):
+ eh = errorhandler.val
try:
resp = [""]
while True:
break
except restart, i:
handler = i.handle
+ except Exception, i:
+ if eh is None:
+ raise
+ handler = wraphandler(eh, sys.exc_info())
+ eh = None
req.commit(startreq)
return resp
finally: