a = 1
for link in result:
try:
signal.alarm(5)
time.sleep(a)
signal.alarm(0)
a = a + 1
print ('выполнено')
except:
pass
class TimeoutException(Exception):
pass
def timeout_handler(signum, frame):
raise TimeoutException
signal.signal(signal.SIGALRM, timeout_handler)
for link in result:
signal.alarm(10)
try:
( Выполнение вашей функции)
except TimeoutException:
continue # continue the for loop if function A takes more than n second
else:
signal.alarm(0)
если код выполняется дольше n секунд