[pygtk] Wait until a thread is ended
abel deuring
adeuring at gmx.net
Fri Sep 29 04:03:38 WST 2006
Adolfo González Blázquez wrote:
> Hello,
>
> I would like to know if someone can point me a solution to make a
> function run as a separate thread, and wait until it is ended, without
> blocking the gui.
>
> In my application, i'm getting a long file listing using glob(), and i
> want this function to run as a thread, so the user can stop it using a
> button in the gui (right now, the gui freezes till glob is ended), and
> then run another function to fill the treeview (this now works without
> blocking the gui, using generators). .
>
> Any idea will be really appreaciated.
import threading
import time
def threadfunction():
# thread: do nothing for ca. 10 seconds
stoptime = time.time() + 10.0
while time.time() < stoptime:
print "thread: running"
time.sleep(1)
print "thread: ending"
t = threading.Thread(target=threadfunction)
t.start()
while t.isAlive():
print "waiting for thread"
time.sleep(1.2)
HTH
Abel
More information about the pygtk
mailing list