Rate limiting - kombu.utils.limits

kombu.utils.limits

Token bucket implementation for rate limiting.

class kombu.utils.limits.TokenBucket(fill_rate, capacity=1)

Token Bucket Algorithm.

See http://en.wikipedia.org/wiki/Token_Bucket Most of this code was stolen from an entry in the ASPN Python Cookbook: http://code.activestate.com/recipes/511490/

Thread safety

This implementation may not be thread safe.

can_consume(tokens=1)

Return True if the number of tokens can be consumed from the bucket.

capacity = 1

Maximum number of tokensin the bucket.

expected_time(tokens=1)

Return the time (in seconds) when a new token is expected to be available.

This will also consume a token from the bucket.

fill_rate = None

The rate in tokens/second that the bucket will be refilled

timestamp = None

Timestamp of the last time a token was taken out of the bucket.

Table Of Contents

Previous topic

Evented I/O - kombu.utils.eventio

Next topic

Compat. utilities - kombu.utils.compat

This Page