throttled_request — the module containing the objects to throttle

This module provides the class representing the requests to throttle.

ThrottledRequest — the throttled request object

class requests_throttler.throttled_request.ThrottledRequestAlreadyFinished(msg)

Exception that occurs when a finished is tried to change some attributes to a finished throttled request

Parameters:msg (string) – the message
class requests_throttler.throttled_request.ThrottledRequest(request)

This class represents a throttled request

Parameters:
  • request (requests.PreparedRequest) – the prepared request to throttle
  • finished (boolean) – the flag that indicates if the request has been sent and a response has been received or an exception occured
  • response (requests.Response) – the response corresponding to the request
  • exception (Exception) – the exception occured during the request (None if no exceptions occured)
  • not_done (threading.Condition) – the condition on which to wait to have the response an to make the object thread-safe
__init__(request)

Create a throttled request with the given prepared request

Parameters:request (requests.PreparedRequest) – the prepared request to throttle
request

The corresponding prepared request

Getter:Returns request
Type:requests.PreparedRequest
finished

The flag that indicates if the request has been processed

Getter:Returns finished
Type:boolean
response

The response obtained by processing the request

Getter:

Returns response

Setter:

Sets the response received after the processing of the request

Raise:
ThrottledRequestAlreadyFinshed:
 if the throttled request has already finished
Type:

requests.Response

exception

Return the exception that occurs by processing the request (blocking)

Getter:

Returns exception

Setter:

Sets the exception raised during the processing of the request

Raise:
ThrottledRequestAlreadyFinshed:
 if the throttled request has already finished
Type:

Exception

get_response(timeout=0)

Return the response obtained by processing the request

If timeout is None it waits until a response has been obtained or an execption occurs. When a response has been obtained it is returned, if an exception occurs it is raised. If timeout is not None and no response still hasn’t been obtained after the expiration of timeout, then None is returned.

Parameters:timeout (float) – the timeout value in seconds (default: 0)
Returns:response or None
Return type:requests.Response
get_exception(timeout=0)

Return the exception that occurs by processing the request

If timeout is None it waits until a response has been obtained or an execption occurs. If an exception occurs it is returned otherwise None is returned. If timeout is not None and no response still hasn’t been obtained None is returned.

Parameters:timeout (float) – the timeout value in seconds (default: 0)
Returns:exception or None
Return type:Exception