Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75127
| 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-23 23:46 -0700 |
| Subject | Re: My sys.excepthook dies painfully |
| From | Jason Swails <jason.swails@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12267.1406184424.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On Wed, Jul 23, 2014 at 6:30 PM, Steven D'Aprano < steve+comp.lang.python@pearwood.info> wrote: > On Wed, 23 Jul 2014 13:02:51 -0700, Jason Swails wrote: > > > 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... > > Dammit, it's a Heisenbug... now it's gone away for me too. > > http://c2.com/cgi/wiki?HeisenBug > > > 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. > Looking at your code, it would seem like the shutdown process would happen when you call the original excepthook function (although Python quits whether or not that excepthook is called). How frequently do you observe this Heisenbug? The ones I've encountered were fairly reproducible, although those were more often caused by uninitialized variables or overwriting arrays -- not race conditions like this would seem to be (although unless it's threaded, how do we get a race condition?). Looking at the logging source code, threading is used, although it appears at a cursory glance to be more of a case of handling threaded applications rather than actually using threads to do any kind of work. A possible idea is to throw in a time.sleep(1) call after the call to mylogger.exception to see if that delays interpreter shutdown long enough for mylogger.exception to resolve. Of course if you can't reproduce the bug often enough, it'll be hard to tell if you've fixed it. The most unreliable Heisenbug I've ever fixed still happened ~1/3 of the time, so it was pretty obvious when I fixed it... All the best, Jason
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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