Skip to main content

Implements a counter whose value decays over time

Project description

Implements a counter whose value decays over time

DecayCounter() objects store a float, which decays over time with the given decay rate.
Decay rate is expressed as a half-life, ie. after half_life seconds, the value is halved.
The decay is automatically accounted for on a get() operation, no background thread or other out-of-band
timekeeping is used.

Note that while a set() operation is provided, it is not safe to use in a read-modify-write pattern,
as you would lose the decay that should have occurred between the read and the write.
You should instead use modify() for such operations, which takes a callable that should perform the operation
and return the result.

If one of the following libraries is installed, monotonic time will be used by default:
If you would like to enforce this as a requirement, use the monotonic=True flag.
Conversely, if you would like to force the use of wall clock time.time() even when monotonic is available,
use monotonic=False. Note this is probably a bad idea
(for example, your values will jump up wildly if the system time is changed backwards).

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
decay-0.0.1421587592.tar.gz (1.4 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page