utils — utilities

This module provides some utilities used by other modules.

requests_throttler.utils.locked(lock)

Decorator usefull to access to a function with a lock named lock

Parameters:lock (threading.Lock or threading.Condition) – the name of the lock to use
Returns:the decorated function

Timer — the timer object

class requests_throttler.utils.NoCheckpointSetError(msg)

Exception that occurs when no checkpoint is set and it is needed

Parameters:msg (string) – the message
class requests_throttler.utils.Timer(start=None, checkpoint=None)

This class provides an utility to calculates elapsed time since a start/check point

Parameters:
  • start (float) – the starting time of the timer
  • checkpoint (float) – the last checkpoint of the timer
__init__(start=None, checkpoint=None)

Create the timer with the given starting time and an eventual checkpoint

Parameters:
  • start (float) – the starting time of the timer (default: now)
  • checkpoint (float) – the last checkpoint of the timer (default: None)
start

The timer starting time

Getter:Returns start
Type:float
checkpoint

The last checkpoint

Getter:Returns checkpoint
Setter:Sets the checkpoint
Type:float
total_elapsed()

Return the elapsed time since the timer starting time

Returns:the total elapsed time since the starting time of the timer
Return type:float
elapsed()

Return the elapsed time since the last checkpoint

Returns:

the elapsed time since the last checkpoint

Return type:

float

Raises:
NoCheckpointSetError:
 if checkpoint is None
get_elapsed_and_set_checkpoint(change=True, new_checkpoint=None)

Return the elapsed time since the last checkpoint and change the checkpoint

The checkpoint is changed with new_checkpoint if change is True. If new_checkpoint is None, then to checkpoint is assigned the current time.

Parameters:
  • change (boolean) – the flag that indicates if the checkpoint is to be changed (default: True)
  • new_checkpoint (float) – the new checkpoint to assign (default: None)
Returns:

the elapsed time since the last checkpoint

Return type:

float

Raise:
NoCheckpointSetError:
 if checkpoint is None

Table Of Contents

Previous topic

throttler — the module containing the throttlers

This Page