This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description
[![Build Status](https://travis-ci.org/edgeware/python-circuit.svg?branch=master)](https://travis-ci.org/edgeware/python-circuit)

A circuit breaker according to the logic outline in Michael T. Nygard's
great book [Release It!](http://www.amazon.com/Release-It-Production-Ready-Pragmatic-Programmers/dp/0978739213)

Read: http://en.wikipedia.org/wiki/Circuit_breaker_design_pattern

The circuit breaker monitors communication with a remote peer and in
the case of a high error rate may break the circuit and not allow
further communication for a short period. After a while the breaker
will let through a single request to probe to see if the peer feels
better. If it does, it will close the circuit and allow requests once
again. If not, it will open the circuit again.

A `CircuitBreakerSet` can handle the state for multiple peers at the
same time. Use the `context` method to pick which peer to track. The
first argument is used to identify the peer. Make it a string of some
kind, since it will be used to identify the peer in logs.

Below is a small example of how the circuit breaker can be used:

```python
import logging
import time

from circuit import CircuitBreakerSet

circuit_breaker = CircuitBreakerSet(time.time, logging.getLogger(
'circuit-breaker'))
circuit_breaker.handle_error(ValueError)

def fn(circuit_breaker):
try:
with circuit_breaker.context('my-remote-peer'):
raise ValueError('oh no')
except CircuitOpenError:
# the circuit was open so we did not even try to communicate
# with the remote service.
raise
```

If you call `fn` often enough the circuit breaker will open and
`CircuitOpenError` will be raised.

The `CircuitBreakerSet` class takes a few keyword arguments:

* `time_unit` (default 60) -- Number of seconds to sample seconds over.
* `maxfail` (default 3) -- Number of seconds that is allowed over a time unit.
* `reset_timeout` (default 10) -- Seconds that the circuit is open before
going into half-open mode.

It is also possible to create a single instance of a circuit breaker. The
`circuit.CircuitBreaker` class takes the following arguments:

* `clock` -- A callable that returns the time in seconds.
* `log` -- a `logging.Logger` object used for logging.
* `error_types` -- A list of error types that are treated as errors.
* `maxfail` -- Number of seconds that is allowed over a time unit.
* `reset_timeout` -- Seconds that the circuit is open before
going into half-open mode.
* `time_unit` -- Number of seconds to sample seconds over.


# Twisted Support #

There's also support for using the circuit breaker with Twisted. Note that
the circuit breaker still use pythons standard logging framework. Example:

```python
import logger

from circuit import TwistedCircuitBreakerSet

circuit_breaker = TwistedCircuitBreakerSet(reactor, logging.getLogger(
'circuit-breaker'))
```

(The `TwistedCircuitBreakerSet` adds support for `defer.returnValue`
which uses exceptions internally.)

# License #

Copyright 2012 Edgeware AB.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


# Thanks #

* Michael Nygard, http://www.michaelnygard.com/ for writing the Release It!
book that outlines the circuit breaker pattern

* Edgeware, http://www.edgeware.tv/ for sponsoring the development of
python-circuit.
Release History

Release History

0.1.9

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.8

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1-dirty

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.0-dirty

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
python_circuit-0.1.9-py2-none-any.whl (9.0 kB) Copy SHA256 Checksum SHA256 py2 Wheel Jul 11, 2016
python-circuit-0.1.9.tar.gz (6.2 kB) Copy SHA256 Checksum SHA256 Source Jul 11, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting