painful debugging: techniques?

Hung Jung Lu hungjunglu at yahoo.com
Wed Apr 7 10:21:09 EDT 2004


"Roger Binns" <rogerb at rogerbinns.com> wrote in message news:<a3fck1-s7k.ln1 at home.rogerbinns.com>...
> 
> I do two things.  One is that I catch exceptions and print out the
> variables for each frame, in addition to the traceback.  The recipe
> is at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52215

I think this will not work for the original poster's case. His
exception happens at the moment of garbage collection, out of his
control. That is, the exception is not coming from one of his
statements, so he can't wrap a try...except block around it. Example:

import weakref

class A: pass

def f():
    a = A()
    w = weakref.ref(a, None)

try:
    f()
except:
    print 'This will never be printed'

--------------------------

The original poster spent 9 hours to find the source of this bug. So
it is a tough problem, and it may well happen to other people. The
question now is: how can we stop this from happening to other people?

This bug does not seem to be catchable by sys.excepthook, which makes
it even tougher.

So far, I think Peter Otten's approach (search through the source
code) may be the most practical way. The fact that this bug cannot be
caught with sys.excepthook should probably be considered a bug in
Python?

I guess the only consolation is that this kind of system bugs don't
seem to happen too often. :)

regards,

Hung Jung



More information about the Python-list mailing list