Movatterモバイル変換


[0]ホーム

URL:


homepage

Message91243

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Authorundercoveridiot
Recipientsellisj, mwh, tiagoaoa, undercoveridiot
Date2009-08-03.21:59:31
SpamBayes Score2.620919e-07
Marked as misclassifiedNo
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
DateUserActionArgs
2009-08-03 21:59:33undercoveridiotsetrecipients: +undercoveridiot,mwh,ellisj,tiagoaoa
2009-08-03 21:59:33undercoveridiotsetmessageid: <1249336773.45.0.48918875378.issue1230540@psf.upfronthosting.co.za>
2009-08-03 21:59:32undercoveridiotlinkissue1230540 messages
2009-08-03 21:59:31undercoveridiotcreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp