-import env
+ import sys, traceback
++from . import env
+
__all__ = ["restart"]
class restart(Exception):
if hasattr(self.bk, "close"):
self.bk.close()
- import resp
+ def defaulterror(req, excinfo):
++ from . 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:
try:
resp = iterproxy(handler(req))
break
- except restart, i:
+ except restart as i:
handler = i.handle
- except Exception, i:
++ except Exception as i:
+ if eh is None:
+ raise
+ handler = wraphandler(eh, sys.exc_info())
+ eh = None
req.commit(startreq)
return resp
finally:
- from . import dispatch, proto
-import dispatch, proto, env
++from . import dispatch, proto, env
__all__ = ["skeleton", "skelfor", "setskel", "usererror"]
import threading, time, pickle, random, os
- from . import cookie
-import cookie, env
++from . import cookie, env
__all__ = ["db", "get"]