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


Groups > comp.lang.python > #75096

Re: My sys.excepthook dies painfully

Subject Re: My sys.excepthook dies painfully
From Jason Swails <jason.swails@gmail.com>
Date 2014-07-23 13:02 -0700
References <53cf60d3$0$29897$c3e8da3$5496439d@news.astraweb.com> <53cf6867$0$29897$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmrxZPS6TxZPihU4iShEYJ7NzzYnXi4WFXk3MYbpSp3-yQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.12247.1406145777.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Jul 23, 2014, at 1:02 AM, Chris Angelico <rosuav@gmail.com> wrote:

> On Wed, Jul 23, 2014 at 5:46 PM, Steven D'Aprano <steve@pearwood.info> wrote:
>> On Wed, 23 Jul 2014 07:14:27 +0000, Steven D'Aprano wrote:
>> 
>>> I have some code which sets up a logger instance, then installs it as
>>> sys.excepthook to capture any uncaught exceptions:
>> 
>> Oh! I should have said, I'm running Python 2.6.
> 
> Ah! I tried it in 2.7 and it seemed to work. One moment...
> 
> huix@huix:~$ python mylogging.py
> Traceback (most recent call last):
>  File "mylogging.py", line 24, in <module>
>    foo  # Die with uncaught NameError.
> NameError: name 'foo' is not defined
> huix@huix:~$ python -V
> Python 2.6.6
> huix@huix:~$ tail /var/log/syslog
> ...
> Jul 23 18:01:49 huix INFO: started logging [mylogging]
> Jul 23 18:01:49 huix INFO: installing error handler [mylogging]
> Jul 23 18:01:49 huix ERROR: Uncaught <type 'exceptions.NameError'>:
> name 'foo' is not defined [mylogging]#012None
> 
> Still not sure what's going on. Odd.

Works for me, too:

swails@batman ~ $ python2.6 mylogging.py 
Traceback (most recent call last):
  File "mylogging.py", line 24, in <module>
    foo  # Die with uncaught NameError.
NameError: name 'foo' is not defined
swails@batman ~ $ sudo tail /var/log/messages 
...
Jul 23 16:02:30 batman INFO:started logging [mylogging]
Jul 23 16:02:30 batman INFO:installing error handler [mylogging]
Jul 23 16:02:30 batman ERROR:Uncaught <type 'exceptions.NameError'>: name 'foo' is not defined [mylogging]

I tried it with python2.2 through python2.7 (python 2.2 and earlier did not have the logging module).

I'm not sure how the "mylogger" variable is getting set to None in your my_error_handler callback, but I don't see how that can possibly be happening with the provided code...

All the best,
Jason

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