0

I'm reading emails with a for loop.
It looks something like:

for mail in mail_list:
    # When it takes more than 30 secs, call handle_timeout function
    timer = threading.Timer(30, handle_timeout)
    timer.start()
    self.read_single_mail(mail)
    timer.cancel()

When implementing handle_timeout function, how can I do continue operation for the loop?

Or if there is another good way to achieve this other than timer, please let me know.

=====EDITED=====

I tried with some more code,

def handle_timeout:
    raise TimeoutError

for mail in mail_list:
    # When it takes more than 30 secs, call handle_timeout function
    try:
        timer = threading.Timer(30, handle_timeout)
        timer.start()
        self.read_single_mail(mail)
        timer.cancel()
    except TimeoutError:
        continue

But this also fails.

I expected that after 30 secs TimeoutError will be raised, and it will execute the continue operation.

yoon
  • 1,177
  • 2
  • 15
  • 28

0 Answers0