wwwclient
wwwclient copied to clipboard
Retry on connection time out
The default client sometimes generates a socket.timeout: timed out
when the connection times out. Clients should have a retry policy that retries 5 times with an increasing delay, specified in an array [1,2,3,4,5]
(wait 1s for the first retry, 2s for the second retry, etc.).
If after the 5 retries, the connection is still timing out, then an exception should be raised, and intercepted at the Session level. The transaction should then be set as timed out
(and there should be a Transaction.hasTimedOut()
method).
Usage scenario would be as follows:
from wwwclient import *
# Starts a session that times out
s = session("http://ahostthattimesout.org")
# Gets the transaction object
t = s.last()
# The transaction has timed out
assert t.hasTimedOut()
# and has no data
assert t.data() is None
# We retry the transaction
t.retry()
# s.retry() should do the same
here is an example of a backtrace for a socket timeout errror:
Traceback (most recent call last):
File "/home/sebastien/Projects/Local/lib/python/wwwclient/browse.py", line 653, in get
transaction.do()
File "/home/sebastien/Projects/Local/lib/python/wwwclient/browse.py", line 406, in do
headers=request.headers().asHeaders()
File "/home/sebastien/Projects/Local/lib/python/wwwclient/defaultclient.py", line 29, in GET
return self._request(url, headers, "GET")
File "/home/sebastien/Projects/Local/lib/python/wwwclient/defaultclient.py", line 57, in _request
response = self._performRequest()
File "/home/sebastien/Projects/Local/lib/python/wwwclient/defaultclient.py", line 137, in _performRequest
raise e
socket.timeout: timed out