#!/usr/bin/env python
import thread

import gobject
gobject.threads_init()

import gtk
gtk.gdk.threads_init()

def main_quit():
    gtk.gdk.threads_enter()
    try:
        gtk.main_quit()
    finally:
        gtk.gdk.threads_leave()

def nonmain_thread():
    print "threads work"
    gobject.idle_add(main_quit)

thread.start_new_thread(nonmain_thread, ())
gtk.main()

