Skip to main content

Retry decorator for both synchronous and asynchronous functions.

Project description

PyPI version

Retry decorator

Usage

#!/usr/bin/env python3

import sys
from retry_decorator import retry, RetryHandler


def throw_err(msg):
    print('hello', file=sys.stderr)
    raise Exception('throwing err for {}'.format(msg))


def callback(msg):
    print('callback called: {}'.format(msg), file=sys.stderr)


@retry(Exception, tries=3, timeout_secs=0.1)
def test_retry_via_decorator():
    throw_err('retry-via-deco')


def test_retry_via_instance():
    cbe = {
        Exception: lambda: callback('retry-via-instance')
    }
    retry(tries=3, callback_by_exception=cbe)(throw_err)('retry-via-instance')


def test_retry_via_instance2():
    cbe = {
        Exception: lambda: callback('retry-via-instance2')
    }
    RetryHandler(tries=3, callback_by_exception=cbe)(throw_err, 'retry-via-instance2')


if __name__ == '__main__':
    try:
        test_retry_via_decorator()
    except Exception as e:
        print('Received the last exception')

    try:
        test_retry_via_instance()
    except Exception as e:
        print('Received the last exception')

    try:
        test_retry_via_instance2()
    except Exception as e:
        print('Received the last exception')

Building

python3 -m pip install --user --upgrade build
python3 -m build

Contribute

Best contribute to upstream project, but it might be abandoned. Also its defaults will be different from this project, unless PR21 (which is the reason for this fork) is accepted.

So... it's up to you which project you raise your PR against, but contributions are welcome.

Credits

This project is largely influenced & sourced from https://github.com/pnpnpn/retry-decorator and https://gitlab.com/ramil.minnigaliev/the-retry

See also

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

retry_deco-0.0.2.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

retry_deco-0.0.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file retry_deco-0.0.2.tar.gz.

File metadata

  • Download URL: retry_deco-0.0.2.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for retry_deco-0.0.2.tar.gz
Algorithm Hash digest
SHA256 580c29d7a1cb29fd9a957bccbefcb7617f6fd3acf2b5c15708bb93868f02f84a
MD5 4129756c8d7154b19f39e3c5d6608c1c
BLAKE2b-256 cc99261df8b2ba92616584d9dbe44bfa3fbd5b6b35265a78cc901fc81218eaad

See more details on using hashes here.

File details

Details for the file retry_deco-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: retry_deco-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for retry_deco-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 35a8ec05a964fb1c7925f5ae70c83a84888ffc0c7988d7d17a31dd639e860daf
MD5 b12d20957d8fb7b9cb7348a232b08d1a
BLAKE2b-256 b07b8bf868f9674806f4b0b7d74e81b7ffd1b0b41f8ce67a21ed283f953b485a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page