Hello to all python lovers! Such a question: how do you know that the thread has completed its execution?

def proc(): for i in range(1000000): pass p1 = threading.Thread(target=proc) p1.start() p1.join() 

1 answer 1

  1. The join () method for a thread only works after the thread has completed.

    Accordingly, the code that must be executed after the completion of the stream, you can simply put after the line with join ().

  2. The isAlive () method for a thread returns True if the thread is currently running, otherwise False.

    Accordingly, if p1.isAlive () returned False, then the stream p1 has either not yet been started or has already terminated.