what value isAlive (), when a python 3.x process ends?

1

When it is alive, an isAlive process takes the value of True but when that process ends what value does it take?

When I code if t.isAlive == True: if it works because the process is alive but when if t.isAlive == False: does not do anything

I guess the process returns False upon completion of the process which is what I need to do x action. Or is there another instruction or way of knowing when the process ends?  thanks

from threading import Timer
opcion = -1
def motor01():
    print ("fin motor 1\n")

def motor02():
    print ("fin motor 2\n")

while (opcion !=0 ):
    opcion = int (input("opcion deseada "))
    if opcion == 1:
        t = Timer(10.0, motor01)
        t.start() # after 30 seconds, "hello, world" will be printed
        if t.isAlive()== False:
            print ("realizar una acción cuando isAlive() detecte fin de proceso")
    if opcion == 2:
        t = Timer(10.0, motor02)
        t.start() # after 30 seconds, "hello, world" will be printed
        if t.isAlive() == False:
            print ("realizar una acción cuando isAlive() detecte fin de proceso")
    
asked by sergio searching 24.08.2017 в 21:16
source

1 answer

0

According to the Python3x documentation, the function to call is is_alive() , isAlive() comes from previous versions and can still be used but I would recommend you use the first one:

  

is_alive () Return whether the thread is alive.

     

This method returns True just before the run () method starts until   just after the run () method terminates. The module function   enumerate () returns to list of all alive threads.

That is, return True while the Timer is active.

Beyond this, regarding your code, a comment: You are always configuring the same variable for each Timer , so the t.is_alive() will always be the last Timer instantiated. If the idea is that within a cycle several Threads are installed and you need to verify each one to know if it is active, you should handle everything with a list or a dictionary.

    
answered by 25.08.2017 в 04:34