I have a function func and that func can run from 2 to 8 seconds, and i have interval.
both of func and interval is Multithreading
if func runs less than 5 seconds loop next, if func takes greater than 5 seconds break continue loop.
How can I do that? Thanks.
def func():
global che
x = random.randint(2, 8)
time.sleep(x)
print('Time sleep: ', x)
che = True
def interval(tg):
global che2
time.sleep(tg)
print('INTERVAL: ', tg)
che2 = True
inter = 5
for i in range(1, 6):
che = False
che2 = False
print('-------------------------------STEP--------------------------------')
T1 = threading.Thread(target=interval, args=(inter,))
T2 = threading.Thread(target=func)
T1.start()
T2.start()
T1.join()
T2.join()
if che or che2:
continue
I want either one of the two to work.