I'm using threading.Thread
to multi-thread my code.
I want to catch Timeout exception
if at least 1 of the Threads did not finish their work in X seconds.
I found some answers here, describing how to deal with that, but most of them were UNIX compatible, whereas I'm using Windows platform.
Code for example:
from threading import Thread
from time import sleep
def never_stop():
while True:
print 'a'
sleep(5)
print 'b'
return
t1 = Thread(target=never_stop)
t1.start()
t2 = Thread(target=never_stop)
t2.start()
t3 = Thread(target=never_stop)
t3.start()
t1.join(2)
t2.join(2)
t3.join(2)
I tried to set timeout in the join
method but it was useless..
Any ideas?