M
M
meim2021-05-16 11:36:10
Python
meim, 2021-05-16 11:36:10

How to continue executing a Python program on an error in a FOR loop?

It is necessary that in case of any error in any of the functions - wait 5 seconds and continue execution without going to the next cycle, with the same ftid.
Now, in case of an error, the processing of functions with this ftid will be skipped.
How to do it right.

for ftid in range(begin_ftid, end_ftid):
        try:
           f1(ftid)
           f2(ftid)
           f3(ftid)
              
        except Exception:
            time.sleep(5)
            pass

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
o5a, 2021-05-16
@meim

for ftid in range(begin_ftid, end_ftid):
    while True:
        try:
            f1(ftid)
            f2(ftid)
            f3(ftid)

        except Exception:
            time.sleep(5)
            continue
        break

S
soremix, 2021-05-16
@SoreMix

Wrap each function in try ... except, or add the same inside the functions themselves

V
Vladimir Korotenko, 2021-05-16
@firedragon

I would do this: the program works until the queue is empty, objects with the following parameters are added to the queue.
I'd
Retrycount
Delay
Status
If something went wrong, an error status is set in the exception handler and the number of attempts is reduced. Well, set the time after which to try. The loop is infinite, but with the exit condition at the end of the queue or at 0 number of repetitions. Additionally, you can add an error message to each attempt and display them on exit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question