Mercurial > public > mercurial-scm > hg
comparison mercurial/keepalive.py @ 40043:6509fcec830c
url: allow to configure timeout on http connection
By default, httplib.HTTPConnection opens connection with no timeout.
If the server is hanging, Mercurial will wait indefinitely. This may be an
issue for automated scripts.
Differential Revision: https://phab.mercurial-scm.org/D4878
author | C?dric Krier <ced@b2ck.com> |
---|---|
date | Thu, 04 Oct 2018 11:28:48 +0200 |
parents | 5e5b06087ec5 |
children | 41506e3b04ee |
comparison
equal
deleted
inserted
replaced
40042:208303a8172c | 40043:6509fcec830c |
---|---|
170 return list(self._hostmap.get(host, [])) | 170 return list(self._hostmap.get(host, [])) |
171 else: | 171 else: |
172 return dict(self._hostmap) | 172 return dict(self._hostmap) |
173 | 173 |
174 class KeepAliveHandler(object): | 174 class KeepAliveHandler(object): |
175 def __init__(self): | 175 def __init__(self, timeout=None): |
176 self._cm = ConnectionManager() | 176 self._cm = ConnectionManager() |
177 self._timeout = timeout | |
177 self.requestscount = 0 | 178 self.requestscount = 0 |
178 self.sentbytescount = 0 | 179 self.sentbytescount = 0 |
179 | 180 |
180 #### Connection Management | 181 #### Connection Management |
181 def open_connections(self): | 182 def open_connections(self): |
232 h.close() | 233 h.close() |
233 self._cm.remove(h) | 234 self._cm.remove(h) |
234 h = self._cm.get_ready_conn(host) | 235 h = self._cm.get_ready_conn(host) |
235 else: | 236 else: |
236 # no (working) free connections were found. Create a new one. | 237 # no (working) free connections were found. Create a new one. |
237 h = http_class(host) | 238 h = http_class(host, timeout=self._timeout) |
238 if DEBUG: | 239 if DEBUG: |
239 DEBUG.info("creating new connection to %s (%d)", | 240 DEBUG.info("creating new connection to %s (%d)", |
240 host, id(h)) | 241 host, id(h)) |
241 self._cm.add(host, h, 0) | 242 self._cm.add(host, h, 0) |
242 self._start_transaction(h, req) | 243 self._start_transaction(h, req) |