problem on waiting exit thread and write on file
Flyzone
flyzone at technologist.com
Wed Jun 13 11:48:51 EDT 2007
I have a list of parameters.
I need to run in thread a command, one thread for one parameter.
So i made a for loop, creating 5 threads and waiting their stop with:
for parameter in parameters
Thread{
....
write on BW2
....
}
Main {
open file BW2 for write
..... (creating list of thread with a counter)....
Stopped=False
while (Stopped == False):
if not thread5.isAlive():
if not thread4.isAlive():
if not thread3.isAlive():
if not thread2.isAlive():
if not thread1.isAlive():
Stopped=True
if (Stopped == False):
time.sleep(0.3)
......
close file BW2
}
Somethimes i get however the error that i can't write on a file
already closed
There is a way more easy to wait that all children exit and to run a
queue of threads?
I tried also this:
a=0
while (a == 0):
try:
os.waitpid(-2, 0)
except OSError, exc:
# all CHILD finished
a=1
but the same problem persist. The only way to don't have error is to
had a time.sleep(4) before closing the file from the main program.
More information about the Python-list
mailing list