Skip to content

Commit 110f8f7

Browse files
committed
feat(gcm) add timeout to gcm request.
1 parent 1ca573b commit 110f8f7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

gcm/gcm.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,19 @@ class GCM(object):
103103
MAX_BACKOFF_DELAY = 1024000
104104
# TTL in seconds
105105
GCM_TTL = 2419200
106+
# Request timeout in seconds
107+
REQUEST_TIMEOUT = 2.5
106108

107-
def __init__(self, api_key, url=GCM_URL, proxy=None):
109+
def __init__(self, api_key, url=GCM_URL, proxy=None, timeout=None):
108110
""" api_key : google api key
109111
url: url of gcm service.
110112
proxy: can be string "http://host:port" or dict {'https':'host:port'}
111113
"""
112114
self.api_key = api_key
113115
self.url = url
116+
if timeout is None:
117+
timeout = self.REQUEST_TIMEOUT
118+
self.timeout = timeout
114119

115120
if isinstance(proxy, str):
116121
protocol = url.split(':')[0]
@@ -186,7 +191,8 @@ def make_request(self, data, is_json=True):
186191

187192
response = requests.post(
188193
self.url, data=data, headers=self.headers,
189-
proxies=self.proxy
194+
proxies=self.proxy,
195+
timeout=self.timeout
190196
)
191197
# Successful response
192198
if response.status_code == 200:

0 commit comments

Comments
 (0)