problem on waiting exit thread and write on file

Flyzone flyzone at
Wed Jun 13 17:48:51 CEST 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

    write on BW2

Main {
   open file BW2 for write
   ..... (creating list of thread with a counter)....
   while (Stopped == False):
          if not thread5.isAlive():
                  if not thread4.isAlive():
                          if not thread3.isAlive():
                                  if not thread2.isAlive():
                                          if not thread1.isAlive():
          if (Stopped == False):
   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:
               while (a == 0):
                               os.waitpid(-2, 0)
                       except OSError, exc:
                               # all CHILD finished
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