Hi,
I have a win32 app that overrides sys.excepthook to capture top level
exceptions and display a dialog with the error. This was working fine until I
had an exception occur in a thread other than the main(gui) thread. My
standard trick for getting the UI to do something from another thread is to
use gobject.add_idle. For some reason this does not work when all the
threading set up has been done.
A very simplified sample of the error is attached. If threading is turned on,
ie a call is made to gtk.threads_init and the gtk.threads_enter, the app
hangs. If the threading is not started, everything works as expected. If
threading is on and the dialog is created and run in the sys.excepthook,
everything works properly.
I have tried this with version 2.8.6 of pygtk and 2.8.14 of gtk on win32. I
have not tried 2.4 or 2.6 versions though either would be acceptable since the
code base is known to work with pygtk 2.4 and gtk 2.4.
Anyone have any ideas?
Thanks,
Chris
import pygtk
import gobject
import gtk, sys, traceback
gtk.threads_init()
def top_level_error_dialog(tracelines):
# display an error message
md = gtk.MessageDialog(buttons=gtk.BUTTONS_OK, message_format=tracelines)
md.set_title('Unexpected Error')
md.run()
md.destroy()
def _top_level_error(type, value, tb):
tracelines = "\n".join(traceback.format_exception(type, value, tb))
del tb, type, value
gobject.idle_add(top_level_error_dialog, tracelines)
def do_error(*args):
test()
def on_wnd_delete(widget, *args):
widget.destroy()
gtk.main_quit()
sys.excepthook = _top_level_error
wnd = gtk.Window()
btn = gtk.Button('Do it')
btn.show()
btn.connect('clicked', do_error)
wnd.add(btn)
wnd.show()
wnd.connect('delete_event', on_wnd_delete)
gtk.threads_enter()
gtk.main()
gtk.threads_leave()
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/