Home>
Def Func1 ():
    # SOME ACTION
    For c in Range (10):
        Time.Sleep (1)
        PRINT ('FUNC1', C)
    Print ('End Func1')
Def Func2 ():
    # Some Other Action
    For i in Range (5):
        Time.Sleep (1)
        PRINT ('FUNC2', I)
    PRINT ('END FUNC2')
DEF Main ():
    Thread1= Threading.Thread (target= FUNC1)
    Thread2= Threading.Thread (target= FUNC2)
    thread1.start ()
    # Time.Sleep (10)
    thread2.start ()
if __name__== '__main__':
    Main ()

It is necessary to suspend the Thread1 stream at the time of completing the Thread2, then resume it in the same condition. Thread1 type fluxes are somewhat, you need to suspend them all.

tried threading.lock (), but did not quite understand the principle of action of this method.

How can I implement it? Thanks in advance.

Well, in such a primitive case, it is enough just to start the global variable of the type to suspend_potions= false and inside the threads check its WHILE state to pause_potions: time.sleep (5). But something I suspect that the real code is actually more complex

andreymal2021-07-22 10:46:43

@Andreymal is good idea, but in this case the stop will occur in a certain place of the first function, although the pause should be carried out in the arbitrary part of the function.

LaKeR2021-07-22 10:54:31

In an arbitrary part, it is impossible to stop, otherwise the python interpreter will also be in the "arbitrary" state and everything will break to hell

andreymal2021-07-22 10:56:46

You also forgot JOIN-s. Without them, your script will end ahead of time, without waiting for the end of the flow work.

CrazyElf2021-07-22 11:55:58