How do I know when all threads are done?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zerge

    How do I know when all threads are done?

    I can launch threads just fine, but then I have to do a time.sleep(n)
    so the main thread from which they where launched will wait for all
    the threads to return.

    How can I detect when all threads are done and then return control to
    the main threads?

    Thanks for your help
  • John Nagle

    #2
    Re: How do I know when all threads are done?

    Zerge wrote:
    I can launch threads just fine, but then I have to do a time.sleep(n)
    so the main thread from which they where launched will wait for all
    the threads to return.
    >
    How can I detect when all threads are done and then return control to
    the main threads?
    >
    Thanks for your help
    Use "join".

    John Nagle

    Comment

    • Christian Heimes

      #3
      Re: How do I know when all threads are done?

      Zerge schrieb:
      I can launch threads just fine, but then I have to do a time.sleep(n)
      so the main thread from which they where launched will wait for all
      the threads to return.
      >
      How can I detect when all threads are done and then return control to
      the main threads?
      import threading

      threads = []

      threads.append( threading.Threa d(...))
      threads.append( threading.Threa d(...))
      threads.append( threading.Threa d(...))

      for thread in threads:
      thread.start()

      # now all threads are running, some might already be done

      for thread in threads:
      thread.join()

      # here all threads are done

      Christian

      Comment

      Working...