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. Usereconnection_intervalto set the delay in seconds; if not set, the SDK defaults to2seconds plus a random sub-second jitter. Usemaximum_reconnection_retriesto limit the number of attempts; if not set, the policy default of10applies.- 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. Usemaximum_reconnection_intervalto cap the backoff delay. If not set, the SDK defaults to a maximum of150seconds. Usemaximum_reconnection_retriesto limit the number of attempts. If not set, the policy default of6applies.- 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.