Failures and retries

When you call a function over a sequence of inputs with, sometimes errors can happen during function execution. Exceptions from within the remote function are propagated to the caller, so you can handle them with a try-except statement (refer to section on custom types for more on how to catch user-defined exceptions):

def f(i):
    raise ValueError()

def main():
        for _ in[1, 2, 3]):
    except ValueError:
        print("Exception handled")

Function retries

You can configure Modal to automatically retry function failures if you set the retries option when declaring your function:

def my_flaky_function():

When used with, each input is retried up to the max number of retries specified.

The basic configuration shown provides a fixed 1s delay between retry attempts. For fine-grained control over retry delays, including exponential backoff configuration, use modal.Retries.

Container crashes

In the case of a container crash on start-up (for example, while handling imports in global scope before the function can be run), the error will be propagated to the caller immediately, since it’s likely a user error.

If a container crashes after start-up (for example, due to an out of memory error), Modal will reschedule the container and any work it was currently assigned, unless the crash rate of the container exceeds a certain limit.