title: Python. Doing some work on background with Gtk GUI
body: <ul>
  <li><strong>python 3.2.2</strong></li>
  <li><strong>gtk3 3.2.2</strong></li>
  <li><strong>python-gobject 3.0.2</strong></li>
  </ul>
  
  <p>I'm trying to display a GUI and do some work in the background. As I understand it should look something like this: </p>
  
  <pre><code>#!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  
  
  import time
  from threading import Thread
  from gi.repository import Gtk, Gdk
  
  class Gui():
          def run(self):
                  self.Window = Gtk.Window()
                  self.Window.set_border_width(8)
                  self.Window.set_title("Некий GUI")
                  self.Window.connect('destroy', lambda x: self.stop())
  
                  self.outBut = Gtk.Button.new_from_stock(Gtk.STOCK_OK)
                  self.outBut.set_size_request(150, 35)
                  self.outBut.connect('clicked', lambda x: self.passfun)
                  self.Window.add(self.outBut)
  
                  self.Window.show_all()
  
          def stop(self):
                  Gtk.main_quit()
  
          def passfun(self):
                  pass
  
  class LoopSleep(Thread):
          def run(self):
                  i = 1
                  while True:
                          print(i)
                          i = i + 1
                          #time.sleep(1)
  
  
  
  gui = Gui()
  gui.run()
  
  loopSleep = LoopSleep()
  loopSleep.start()
  
  Gdk.threads_init()
  Gdk.threads_enter()
  Gtk.main()
  Gdk.threads_leave()
  </code></pre>
  
  <p>But it does not work. Several cycles occurs when you press the button. And the cycle runs after the window is closed. But not together.</p>
  
  <p>What I do wrong?</p>