[pygtk] pygtk fatal exceptions

Guillaume Bouchard guillaume.bouchard at insa-lyon.fr
Fri May 29 20:22:12 WST 2009


Hello,

I want to debug a pygtk program with PDB (the internal python debuger)
because the program raise an exception.

My aim is to be able to directly "jump" to the exception with "python -m
pdb myprogram.py" and then '(c)ontinue' and wait for the exception to be
catch by pdb.

But the pygtk main loop catch every exception, print it and continue
it's life.

Is there an option to change this behavior ? I have found on the
internet about PYGTK_FATAL_EXCEPTIONS, but this does not still work,
there is a patch :

2001-12-12  Matt Wilson  <msw at redhat.com>

        * gtk/pygtk.h (PyGtk_FatalExceptions): remove.

        * gtk/pygtk-private.h (PyGtk_FatalExceptions): remove.

        * gtk/gtkmodule.c (init_gtk): don't bother with
        PYGTK_FATAL_EXCEPTIONS.
        (pygtk_main_quit): remove unused code.

I had read about the use of sys.excepthook, but it only allow me to look
at the exception, but even if I raise it again, the main loop still
catch it.

This is an example program :

import gtk,gobject

def callback():
    raise ValueError

gobject.idle_add(callback)
gtk.main()

and the PDB session :

$ python -m pdb gtk_test.py
> /home/gbouchard/gtk_test.py(1)<module>()
-> import gtk,gobject
(Pdb) continue
Traceback (most recent call last):
  File "gtk_test.py", line 4, in callback
    raise ValueError
ValueError

.. here PDB hang and the gtk_main_loop continue to live. I want the
exception to pass through gtk.main_loop and finish in PDB.

Be able to use pdb to jump directly on an exception is really needed
when you debug pygtk code.

Thank, and sorry for my writing skills...

-- 
Guillaum


More information about the pygtk mailing list