#! /usr/bin/env python

import thread
import glib
import gobject
import gtk

use_main_loop = False

gobject.threads_init()
gtk.gdk.threads_init()

def quit():
    if use_main_loop:
        gtk.main_quit()
    else:
        loop.quit()

def nonmain_thread():
    print "threads work"
    glib.idle_add(quit)

def tick():
    print 'tick'
    return True

thread.start_new_thread(nonmain_thread, ())
glib.timeout_add(1000, tick)

if use_main_loop:
    gtk.main()
else:
    loop = glib.MainLoop()
    loop.run()
