I run a while True loop function in a thread, and I need to terminate the thread from main.
I can't stop the loop with a stop flag because of the function written in another module.
The code looks like this:
import threading
from time import sleep
# This def are in another module
def loop():
while True:
print("Stil looping")
sleep(1)
# Here I define and start the thread
t = threading.Thread(target=loop, args=())
t.start()
# Here is Thinks that happened in my Main
sleep(5)
# Here I try to stop the thread.
t.join()
print("Down")
The output look like this:
Stil looping
Stil looping
Stil looping
Stil looping
Stil looping
Stil looping
Stil looping
Stil looping
Stil looping
Stil looping
Stil looping
...
It doesn't join the thread...
Hope for your help. Thanks.