Python

From ThorstensHome
Revision as of 18:04, 1 December 2012 by WikiSysop (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

python gtk and threads

# testcase to show that closing does not work
import gobject, gtk
from threading import Thread

gobject.threads_init()
program_running=42


def blinker():
  while program_running:
    print program_running
class counter:
  def ev_close(self, widget, event, data=None):
    print "ev_close"
    program_running=False
    quit()
    print "end ev_close"
  def __init__(self):
    self.window=gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.window.connect("delete_event", self.ev_close)
    self.window.show()
    t=Thread(target=blinker)
    t.start()

  def main(self):
    gtk.main()

app=counter()
app.main()

quit() does not return here because a thread is still running