KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm in the process of converting a program from PyGTK to PyGObject introspection for the first time and I've hit a roadblock with threading. I have a process that takes some time to complete, so I pop up a dialog with a progress bar on it and I use a thread to do the process and to update the progress bar. This worked fine with PyGTK but after converting to PyGObject, I get all the usual improper threading weirdness: the program hangs, but it seems to hang in different parts of the process, etc. So I get the impression that something has changed but I can't figure out what. Here's this simple PyGTK progressbar example: http://aruiz.typepad.com/siliconisland/2006/04/threads_on_pygt.html As presented on that page, the code works. I've converted it to PyGObject introspection and I get the same problems as in my program: it hangs, it doesn't properly update the progress bar, etc. import threading import random, time from gi.repository import Gtk, Gdk #Initializing the gtk's thread engine Gdk.threads_init() class FractionSetter(threading.Thread): """This class sets the fraction of the progressbar""" #Thread event, stops the thread if it is set. stopthread = threading.Event() def run(self): """Run method, this is the code that runs while thread is alive.""" #Importing the progressbar widget from the global scope global progressbar #While the stopthread event isn't setted, the thread keeps going on while not self.stopthread.isSet() : # Acquiring the gtk global mutex Gdk.threads_enter() #Setting a random value for the fraction progressbar.set_fraction(random.random()) # Releasing the gtk global mutex Gdk.threads_leave() #Delaying 100ms until the next iteration time.sleep(0.1) def stop(s
Tags (comma-separated)
Save Edits
Cancel