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


Groups > comp.lang.python > #75112

Re: My sys.excepthook dies painfully

References <53cf60d3$0$29897$c3e8da3$5496439d@news.astraweb.com> <53cf6867$0$29897$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmrxZPS6TxZPihU4iShEYJ7NzzYnXi4WFXk3MYbpSp3-yQ@mail.gmail.com> <mailman.12247.1406145777.18130.python-list@python.org> <53d061c1$0$29966$c3e8da3$5496439d@news.astraweb.com>
Date 2014-07-24 11:50 +1000
Subject Re: My sys.excepthook dies painfully
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.12257.1406167091.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Jul 24, 2014 at 11:30 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> However, I think I have a glimmer of an idea for how the global variable
> might be set to None. When the Python interpreter shuts down, it sets
> global variables to None in some arbitrary order. If the excepthook
> function isn't called until after the shutdown process begins, then
> depending on the phase of the moon, it's possible that ``mylogger`` may
> have been set to None by the time it is called.

In other words, the problem changed when you added the NameError
trigger at the bottom of the script?

Would it be possible to snapshot all critical globals with a closure,
to force them to be held? Something like:

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

# Install exception handler.
mylogger.info('installing error handler')
sys.excepthook = handler_gen(mylogger, sys)

It seems crazy, but it might work. It's a guaranteed one-way
connection, saying "this function NEEDS these objects".

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