[pygtk] GObject in thread
Jeffrey Barish
jeff_barish at earthlink.net
Fri Jun 19 04:57:31 WST 2009
I'm trying to get gobject to run a loop in a thread. It hangs. Look at
this code:
# This is the run method of a subclass of threading.Thread.
def run(self):
def tester():
<Do something that allows me to detect that the loop is running>
return True
gobject.timeout_add(1000, tester)
loop = gobject.MainLoop()
# Case 1
#loop.run()
# Case 2
#context = loop.get_context()
#while True:
#context.iteration(True)
# Case 3
context = loop.get_context()
while True:
context.iteration(False)
time.sleep(1.0)
Case 3 works, but the blocking versions, cases 1 and 2, do not.
I think that this statement from the documentation may be significant:
The run() method runs a mainloop until the quit() method is called. If this
is called for the thread of the loop's gobject.MainContext, it will process
events from the loop, otherwise it will simply wait.
Since I create the MainLoop right there, the run is called for the thread of
the loop's MainContext, isn't it? On the other hand, "simply waiting" is
what the code seems to be doing.
--
Jeffrey Barish
More information about the pygtk
mailing list