Rate limiting - kombu.utils.limits

kombu.utils.limits

Token bucket implementation for rate limiting.

copyright:
  1. 2009 - 2012 by Ask Solem.
license:

BSD, see LICENSE for more details.

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)

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

capacity = 1

Maximum number of tokensin the bucket.

expected_time(tokens=1)

Returns the expected time in seconds when a new token should be available.

Warning

This consumes 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

Utilities - kombu.utils

Next topic

Compat. utilities - kombu.utils.compat

This Page