Currently I have been ending loops()
from within the thread.
Nesting if statements
into loops()
... but if there are a lot of loops and nested loops, the statements become very redundant and create clutter. Is there a way to run a timeout thread that can end loops
and return a timeout
value in place of the current work loops
was doing?
import threading
import time
def timeout():
for i in range(10):
time.sleep(0.1)
print('stop all bla loops now')
billy = 'timeout'
def loops():
for i in range(5):
time.sleep(0.1)
print('loop1')
billy = 'loop1 done'
for i in range(5):
time.sleep(0.1)
print('loop2')
billy = 'loop2 done'
for i in range(5):
time.sleep(0.1)
print('loop3')
billy = 'loop3 done'
billy = 'cool'
loops = threading.Thread(target=loops).start()
timeout = threading.Thread(target=timeout).start()