New paste Use cases Explore public pastes Text tools Developer API The Paste Library Security Sign in with Google
PYTHONExample pasteCreated 2026-08-032 viewsNo expiry

Python retry with exponential backoff

Raw New paste
pythonRead-only
1
import time
from functools import wraps

def retry(attempts=3, base_delay=0.25):
    def decorate(function):
        @wraps(function)
        def wrapped(*args, **kwargs):
            for attempt in range(attempts):
                try:
                    return function(*args, **kwargs)
                except TimeoutError:
                    if attempt == attempts - 1:
                        raise
                    time.sleep(base_delay * (2 ** attempt))
        return wrapped
    return decorate
Report abuse

Paste details

Visibility
Public
Size
507 bytes
Protection
Standard link access
Retention
No automatic expiry

Share with confidence

Unlisted links are not searchable, but anyone with the URL can open them. Never paste live credentials or personal data.