Skip to main content

breakers

https://travis-ci.org/elemepi/breakers.svg?branch=master

Usable Circuit Breaker pattern implementation.

Install

$ pip install breakers

Usage

import functools
from breakers import Breaker

def circuit_breaker(time_span=20000, unit=1000, calls_limit=10,
                    error_limit=0.5, retry_time=10000):
    def deco(func):
        # Create breaker
        if not hasattr(func, '__breaker__'):
            func.__breaker__ = Breaker(time_span, unit, calls_limit,
                                       error_limit, retry_time)
        breaker = func.__breaker__

        @functools.wraps(func)
        def wraps(*args, **kwargs):
            if not breaker.is_allow():
                raise RuntimeError('Circuit breaker')

            exc = None
            try:
                return func(*args, **kwargs)
            except Exception as e:
                exc = e
                raise
            finally:
                if exc:
                    breaker.add_failure(1)
                else:
                    breaker.add_success(1)
        return wraps
    return deco

@circuit_breaker()
def f():
    import random
    if random.randint(1, 4) in (1, 2):
        raise ValueError
    return 'succeed'

Metadata

Release files for breakers 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for breakers 0.1.0
File Size Uploaded Provenance Actions
breakers-0.1.0.tar.gz 3.3 kB Without provenance Details for breakers-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for breakers 0.1.0
File Interpreter ABI Platform Actions
breakers-0.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for breakers-0.1.0-py2.py3-none-any.whl

Total release size: 8.7 kB

Release files / breakers-0.1.0.tar.gz

Download URL breakers-0.1.0.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
af332c5b5417cf1a1889ba456a1da0d85aa8e8003e8f93e5bde5835f158f4482
BLAKE2b-256 checksum
How to use checksums
78a0fef4c8d07538edeb68c87b2199dc02c0c4740adfbe271eb3cc2d45221d52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / breakers-0.1.0-py2.py3-none-any.whl

Download URL breakers-0.1.0-py2.py3-none-any.whl
Size 5.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9a61cf5c6477c850efc2916ce3e6ae13a4a8f544b70c8bfdd4be0649409c426b
BLAKE2b-256 checksum
How to use checksums
be5effa1e68eec8fd610b3d661ad48075fc39ba95bf1492a9c898167f32b7e85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for breakers 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page