>> Why doesn't it exit if I hit Ctl-C? It just sits there. I have to
>> hit Ctl-Z then kill %1. My glib_version is (2, 2, 2). I'm running
>> on Solaris 9 should that make a difference.
...
Johan> So, use gtk.main() or file a bug against GMainLoop.main() Maybe
Johan> just installing a timeout handler, say every 100 ms could be
Johan> enough YMMV.
We have non-GUI applications which I am led to believe shouldn't use
gtk.main(). I tried writing a timeout handler:
import gobject
main_loop = gobject.MainLoop()
def timeout(*args):
print args
try:
pass
except KeyboardInterrupt:
main_loop.quit()
sys.exit()
return True
gobject.timeout_add(100, timeout, priority=100)
main_loop.run()
but though it gets called frequently it never sees a KeyboardInterrupt.
Does gtk/gobject swallow that?
I modified my script to call gtk.main() and to raise something other than
KeyboardInterrupt or SystemExit:
import gobject, gtk
main_loop = gobject.MainLoop()
i = 0
def timeout(*args):
global i
i += 1
if i >= 20:
1/0
return True
gobject.timeout_add(100, timeout, priority=100)
try:
gtk.main()
except:
print "!"
A traceback is displayed about the ZeroDivisionError instead of the app
printing "!". I don't see that until I later terminate the app with C-c.
A bit more fiddling led to this slight extra complication using
sys.except_hook without relying on gtk:
import sys
import traceback
import gobject
main_loop = gobject.MainLoop()
i = 0
def timeout(*args):
global i
i += 1
if i >= 50:
1/0
return True
def exc_handler(exc, val, tb):
if exc != KeyboardInterrupt:
traceback.print_exception(exc, val, tb)
sys.exit()
sys.excepthook = exc_handler
gobject.timeout_add(100, timeout, priority=100)
main_loop.run()
In fact, reducing timeout() to
def timeout():
return True
seems sufficient.
Thanks for the suggestions.
--
Skip Montanaro
Got gigs? http://www.musi-cal.com/submit.html
Got spam? http://www.spambayes.org/
[EMAIL PROTECTED]
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/