Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions customerio/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from __future__ import division
from datetime import datetime, timezone
import math
import socket

from requests import Session
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from urllib3.connection import HTTPConnection


class CustomerIOException(Exception):
Expand All @@ -18,6 +20,14 @@ def __init__(self, retries=3, timeout=10, backoff_factor=0.02):
self.timeout = timeout
self.retries = retries

# Set the TCP keepalive settings to the values dicated by our server-side configuration.
HTTPConnection.default_socket_options = ( HTTPConnection.default_socket_options + [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
(socket.SOL_TCP, socket.TCP_KEEPIDLE, 300),
(socket.SOL_TCP, socket.TCP_KEEPINTVL, 60)
]
)

self.http = Session()
# Retry request a number of times before raising an exception
# also define backoff_factor to delay each retry
Expand Down