Message91243
| Author | undercoveridiot |
|---|
| Recipients | ellisj, mwh, tiagoaoa, undercoveridiot |
|---|
| Date | 2009-08-03.21:59:31 |
|---|
| SpamBayes Score | 2.620919e-07 |
|---|
| Marked as misclassified | No |
|---|
| Message-id | <1249336773.45.0.48918875378.issue1230540@psf.upfronthosting.co.za> |
|---|
| In-reply-to | |
|---|
| Content |
|---|
I found that the workaround suggested doesn't work when you have asubclass of threading.Thread and you want to catch everything in themodule that contains the class to a common log.Say you have a module with a socket server that spawns a thread onaccept and you want to log anything that tracebacks in the module. Thisseems to work:import sysimport loggingfrom functools import wrapsdef myExceptHook(type, value, tb): """ Redirect tracebacks to error log """ import traceback rawreport = traceback.format_exception(type, value, tb) report = '\n'.join(rawreport) log.error(report)sys.excepthook = myExceptHook def use_my_excepthook(view): """ Redirect any unexpected tracebacks """ @wraps(view) def run(*args, **kwargs): try: return view(*args, **kwargs) except: sys.excepthook(*sys.exc_info()) return runThen in your thread subclass:class MyThread(threading.Thread): def __init__(self, socket_conn): threading.Thread.__init__(self) self.my_conn = socket_conn @use_my_excepthook def run(self): """ Do stuff """ |
| History |
|---|
| Date | User | Action | Args |
|---|
| 2009-08-03 21:59:33 | undercoveridiot | set | recipients: +undercoveridiot,mwh,ellisj,tiagoaoa | | 2009-08-03 21:59:33 | undercoveridiot | set | messageid: <1249336773.45.0.48918875378.issue1230540@psf.upfronthosting.co.za> | | 2009-08-03 21:59:32 | undercoveridiot | link | issue1230540 messages | | 2009-08-03 21:59:31 | undercoveridiot | create | |
|