> ## Documentation Index
> Fetch the complete documentation index at: https://docs.beam.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Timeouts and Retries

You can customize the default timeout and retry behavior for your tasks.

# Timeouts

### Default Timeouts

Tasks automatically timeout after 20 minutes *if they haven't started running*. This default exists to prevent stuck tasks from consuming compute resources and potentially blocking other tasks in the queue.

### Customizing Timeouts

You can specify your own timeouts. Timeouts can be used for endpoints, task queues, and functions:

```python timeout.py theme={null}
from beam import function
import time


@function(timeout=600) # Override default timeout
def timeout():
    import time

    # Without the timeout specified above, this function would timeout at 300s
    time.sleep(350)


if __name__ == "__main__":
    timeout()
```

# Retries

Beam includes retry logic, which can be customized using the parameters below.

### Max Retries

You can configure tasks to automatically retry based on a specific exception in your app.

In the example below, we'll specify `retries` and `retry_for`:

```python timeout.py theme={null}
from beam import task_queue


@task_queue(retries=2, retry_for=[Exception])  # Override default retry logic
def handler():
    raise Exception("Something went wrong, retry please!")
```

### Retry for Exceptions

When the task is invoked, we'll see the exception get caught and the task automatically retry:

```sh theme={null}
Running task <87067d0e-5900-413b-a3a3-5ee4c85706ad>
Traceback (most recent call last):
  File "/mnt/code/app.py", line 6, in handler
    raise Exception("Something went wrong, retry please!")

Exception: Something went wrong, retry please!
retry_for error caught: Exception('Something went wrong, retry please!')
Retrying task <87067d0e-5900-413b-a3a3-5ee4c85706ad> after Exception exception

Running task <87067d0e-5900-413b-a3a3-5ee4c85706ad>
```
