Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75066

Re: My sys.excepthook dies painfully

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!hq-usenetpeers!hq-usenetpeers.eweka.nl!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'value,': 0.04; 'attribute': 0.07; 'context': 0.07; 'correct.': 0.07; 'none,': 0.07; 'python3': 0.07; 'subject:skip:s 10': 0.07; '%s"': 0.09; 'exception.': 0.09; 'msg': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '23,': 0.16; '24,': 0.16; 'dump': 0.16; 'emit': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'limit,': 0.16; 'nameerror:': 0.16; 'sio)': 0.16; 'stderr': 0.16; 'values:': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'slightly': 0.19; 'cc:addr:python.org': 0.22; 'print': 0.22; 'error': 0.23; 'looks': 0.24; 'cc:2**0': 0.24; 'equivalent': 0.26; 'skip:" 30': 0.26; 'skip:" 40': 0.26; 'this:': 0.26; 'defined': 0.27; 'skip:" 20': 0.27; 'skip:_ 20': 0.27; 'header:In-Reply- To:1': 0.27; 'specifically': 0.29; 'see,': 0.30; 'message- id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; "d'aprano": 0.31; 'steven': 0.31; 'though.': 0.31; 'file': 0.32; 'there.': 0.32; 'stuff': 0.32; '(most': 0.33; 'problem': 0.35; "can't": 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'returning': 0.36; 'method': 0.36; 'system,': 0.38; 'handle': 0.38; 'pm,': 0.38; 'recent': 0.39; 'does': 0.39; 'though,': 0.39; 'skip:t 30': 0.61; 'name': 0.63; 'jul': 0.74; "'foo'": 0.84; 'was:': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=RJsdnUdKrqvnXO7g/tzqc4wcxqa6Z1iI7DW2V6h+BCQ=; b=Gs7YQ5oAzc4dZyiYfcg1G/RaMazm3Pj8ZsbD9Elg85YSUpKSz4Cz8X48dawSQlgct/ +Vu40obtqA2fPQAH4olV+P6Ua5UBbudbDdAhWWlfpSo0wxL8fJf+CPPX9TNmMM47DFHl WTjnWrSalaDqrE5gDG4TBl8l8UC6dKQTgZATtlNDSyy4fPKaQNtbH87NZhDw5BekOz2n XWHRfuxOQ25fbDHKbQuQwTT8XDqpBJQEQfBcyNYdFbweNhrEMq49mupZtmgbBDEgPwRY gef37jMNx2YYF9xescXDwQ/KMIk9arblsegJb0w0BG95R9/VSD70u3Khz/O0i5f10IeO Sp9w==
MIME-Version 1.0
X-Received by 10.220.81.194 with SMTP id y2mr47327980vck.29.1406100996783; Wed, 23 Jul 2014 00:36:36 -0700 (PDT)
In-Reply-To <53cf60d3$0$29897$c3e8da3$5496439d@news.astraweb.com>
References <53cf60d3$0$29897$c3e8da3$5496439d@news.astraweb.com>
Date Wed, 23 Jul 2014 17:36:36 +1000
Subject Re: My sys.excepthook dies painfully
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12223.1406101000.18130.python-list@python.org> (permalink)
Lines 62
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1406101000 news.xs4all.nl 2892 [2001:888:2000:d::a6]:50161
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 6244
X-Received-Body-CRC 2238466761
Xref csiph.com comp.lang.python:75066

Show key headers only | View raw


On Wed, Jul 23, 2014 at 5:14 PM, Steven D'Aprano <steve@pearwood.info> wrote:
> Error in sys.excepthook:
> Traceback (most recent call last):
>   File "/home/steve/mylogging.py", line 28, in my_error_handler
>     mylogger.exception(msg)
> AttributeError: 'NoneType' object has no attribute 'exception'
>
> Original exception was:
> Traceback (most recent call last):
>   [...]
>   File "/home/steve/mylogging.py", line 35, in <module>
>     foo
> NameError: name 'foo' is not defined

I was not able to repro this with the 3.5-messy that I have on this
system, nor a clean 3.4.1 from Debian Jessie. It's slightly different:

rosuav@dewey:~$ python3 mylogging.py
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3.4/logging/__init__.py", line 846, in handle
    self.emit(record)
  File "/usr/lib/python3.4/logging/handlers.py", line 881, in emit
    msg = self.format(record)
  File "/usr/lib/python3.4/logging/__init__.py", line 821, in format
    return fmt.format(record)
  File "/usr/lib/python3.4/logging/__init__.py", line 566, in format
    record.exc_text = self.formatException(record.exc_info)
  File "/usr/lib/python3.4/logging/__init__.py", line 516, in formatException
    traceback.print_exception(ei[0], ei[1], tb, None, sio)
  File "/usr/lib/python3.4/traceback.py", line 169, in print_exception
    for line in _format_exception_iter(etype, value, tb, limit, chain):
  File "/usr/lib/python3.4/traceback.py", line 146, in _format_exception_iter
    for value, tb in values:
  File "/usr/lib/python3.4/traceback.py", line 125, in _iter_chain
    context = exc.__context__
AttributeError: 'NoneType' object has no attribute '__context__'

Original exception was:
Traceback (most recent call last):
  File "mylogging.py", line 24, in <module>
    foo  # Die with uncaught NameError.
NameError: name 'foo' is not defined

(Obviously that's the clean 3.4, but it's the same exception in 3.5.)

>From what I can see, the problem is that sys.exc_info() is returning
None, None, None at this point, and the Logger.exception() method
specifically looks for the currently-being-handled exception. You can
get equivalent functionality with this:

def my_error_handler(type, value, tb):
    msg = "Uncaught %s: %s" % (type, value)
    mylogger.error(msg, exc_info=(type, value, tb))
    sys.__excepthook__(type, value, tb)  # print the traceback to stderr

At least, I think that's correct. It does seem to dump a lot of stuff
into a single line in the log, though.

Can't repro your exact traceback, though, so I don't know what's going on there.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

My sys.excepthook dies painfully Steven D'Aprano <steve@pearwood.info> - 2014-07-23 07:14 +0000
  Re: My sys.excepthook dies painfully Chris Angelico <rosuav@gmail.com> - 2014-07-23 17:36 +1000
  Re: My sys.excepthook dies painfully Steven D'Aprano <steve@pearwood.info> - 2014-07-23 07:46 +0000
    Re: My sys.excepthook dies painfully Chris Angelico <rosuav@gmail.com> - 2014-07-23 18:02 +1000
    Re: My sys.excepthook dies painfully Jason Swails <jason.swails@gmail.com> - 2014-07-23 13:02 -0700
      Re: My sys.excepthook dies painfully Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-24 01:30 +0000
        Re: My sys.excepthook dies painfully Chris Angelico <rosuav@gmail.com> - 2014-07-24 11:50 +1000
          Re: My sys.excepthook dies painfully Steven D'Aprano <steve@pearwood.info> - 2014-07-24 10:12 +0000
            Re: My sys.excepthook dies painfully Chris Angelico <rosuav@gmail.com> - 2014-07-24 20:20 +1000
        Re: My sys.excepthook dies painfully Steven D'Aprano <steve@pearwood.info> - 2014-07-24 05:51 +0000
        Re: My sys.excepthook dies painfully Jason Swails <jason.swails@gmail.com> - 2014-07-23 23:46 -0700
  Re: My sys.excepthook dies painfully dieter <dieter@handshake.de> - 2014-07-24 07:36 +0200

csiph-web