AsyncRetryPolicy Class

Async flavor of the retry policy.

The async retry policy in the pipeline can be configured directly, or tweaked on a per-call basis.

Inheritance
azure.core.pipeline.policies._retry.RetryPolicyBase
AsyncRetryPolicy
azure.core.pipeline.policies._base_async.AsyncHTTPPolicy
AsyncRetryPolicy

Constructor

AsyncRetryPolicy(**kwargs)

Parameters

retry_total
int

Total number of retries to allow. Takes precedence over other counts. Default value is 10.

retry_connect
int

How many connection-related errors to retry on. These are errors raised before the request is sent to the remote server, which we assume has not triggered the server to process the request. Default value is 3.

retry_read
int

How many times to retry on read errors. These errors are raised after the request was sent to the server, so the request may have side-effects. Default value is 3.

retry_status
int

How many times to retry on bad status codes. Default value is 3.

retry_backoff_factor
float

A backoff factor to apply between attempts after the second try (most errors are resolved immediately by a second try without a delay). Retry policy will sleep for: {backoff factor} * (2 ** ({number of total retries} - 1)) seconds. If the backoff_factor is 0.1, then the retry will sleep for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.

retry_backoff_max
int

The maximum back off time. Default value is 120 seconds (2 minutes).

Examples

Configuring an async retry policy.


   from azure.core.pipeline.policies import AsyncRetryPolicy

   retry_policy = AsyncRetryPolicy()

   # Total number of retries to allow. Takes precedence over other counts.
   # Default value is 10.
   retry_policy.total_retries = 5

   # How many connection-related errors to retry on.
   # These are errors raised before the request is sent to the remote server,
   # which we assume has not triggered the server to process the request. Default value is 3
   retry_policy.connect_retries = 2

   # How many times to retry on read errors.
   # These errors are raised after the request was sent to the server, so the
   # request may have side-effects. Default value is 3.
   retry_policy.read_retries = 4

   # How many times to retry on bad status codes. Default value is 3.
   retry_policy.status_retries = 3

   # A backoff factor to apply between attempts after the second try
   # (most errors are resolved immediately by a second try without a delay).
   # Retry policy will sleep for:
   #    {backoff factor} * (2 ** ({number of total retries} - 1))
   # seconds. If the backoff_factor is 0.1, then the retry will sleep
   # for [0.0s, 0.2s, 0.4s, ...] between retries.
   # The default value is 0.8.
   retry_policy.backoff_factor = 0.5

   # The maximum back off time. Default value is 120 seconds (2 minutes).
   retry_policy.backoff_max = 120

   # Alternatively you can disable redirects entirely
   retry_policy = AsyncRetryPolicy.no_retries()

   # All of these settings can also be configured per operation.
   policies.append(retry_policy)
   async with AsyncPipelineClient(base_url=url, policies=policies) as client:
       response = await client._pipeline.run(
           request,
           retry_total=10,
           retry_connect=1,
           retry_read=1,
           retry_status=5,
           retry_backoff_factor=0.5,
           retry_backoff_max=60,
           retry_on_methods=['GET']
       )

Methods

send

Uses the configured retry policy to send the request to the next policy in the pipeline.

sleep

Sleep between retry attempts.

This method will respect a server's Retry-After response header and sleep the duration of the time requested. If that is not present, it will use an exponential backoff. By default, the backoff factor is 0 and this method will return immediately.

send

Uses the configured retry policy to send the request to the next policy in the pipeline.

async send(request)

Parameters

request
PipelineRequest
Required

The PipelineRequest object

Returns

Returns the PipelineResponse or raises error if maximum retries exceeded.

Return type

sleep

Sleep between retry attempts.

This method will respect a server's Retry-After response header and sleep the duration of the time requested. If that is not present, it will use an exponential backoff. By default, the backoff factor is 0 and this method will return immediately.

async sleep(settings, transport, response=None)

Parameters

settings
dict
Required

The retry settings.

transport
Required

The HTTP transport type.

response
PipelineResponse
default value: None

The PipelineResponse object.