On this page

Reconnection Policies for Python-Asyncio SDK

In networked applications, maintaining a stable connection is critical. The PubNub Python-Asyncio Software Development Kit (SDK) provides three reconnection policies to help applications recover from temporary network disruptions.

Default behavior

Default behavior: If you do not set a reconnection policy, PNReconnectionPolicy.EXPONENTIAL is used.

Types of reconnection policies

Choose the policy that best matches your environment and tolerance for retry delays during a network or internet issue.

  • PNReconnectionPolicy.NONE: The SDK does not attempt automatic reconnection when there is a network or internet issue.

    • Use when: You need full control over retry logic or want to fail fast in short‑lived scripts and serverless functions.
  • PNReconnectionPolicy.LINEAR: The SDK attempts to reconnect at a fixed interval until connectivity is restored. Use reconnection_interval to set the delay in seconds; if not set, the SDK defaults to 2 seconds plus a random sub-second jitter. Use maximum_reconnection_retries to limit the number of attempts; if not set, the policy default of 10 applies.

    • Use when: You prefer consistent retry intervals in stable networks where brief outages are expected.
  • PNReconnectionPolicy.EXPONENTIAL (default): The SDK uses the Exponential Backoff algorithm to increase the delay between reconnection attempts progressively. Use maximum_reconnection_interval to cap the backoff delay. If not set, the SDK defaults to a maximum of 150 seconds. Use maximum_reconnection_retries to limit the number of attempts. If not set, the policy default of 6 applies.

    • Use when: You want to reduce load on unstable networks or downstream services by spacing out retries.
Set retry limits explicitly

The Python-Asyncio SDK doesn't enforce upper bounds on maximum_reconnection_retries or maximum_reconnection_interval.

Without limits, misconfigured policies may cause excess network traffic, battery drain, or usage spikes. Always choose values suited to your app.