Reconnection Policies for Python SDK

In networked applications, maintaining a stable connection is critical. The PubNub Python 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.NONE 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 (default): 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 every 3 seconds until connectivity is restored.

    • Use when: You prefer consistent retry intervals in stable networks where brief outages are expected.
  • PNReconnectionPolicy.EXPONENTIAL: The SDK uses the Exponential Backoff algorithm to reconnect when there is a network or internet issue. The SDK uses MINEXPONENTIALBACKOFF = 1 second and MAXEXPONENTIALBACKOFF = 32 seconds. See: https://en.wikipedia.org/wiki/Exponential_backoff for more details.

    • Use when: You want to reduce load on unstable networks or downstream services by spacing out retries.
Last updated on