Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import httplib
import time
from socket import timeout
HOST = "my test host"
start = time.time()
try:
conn = httplib.HTTPConnection(HOST, timeout=0.5)
conn.request(method="GET", url="/tmp/slow.php")
response = conn.getresponse()
content = response.read()
except timeout:
print "Had a timeout!"
end = time.time()
print "Timeout 0.5 time: ", end-start
start = time.time()
try:
conn = httplib.HTTPConnection(HOST, timeout=2.5)
conn.request(method="GET", url="/tmp/slow.php")
response = conn.getresponse()
content = response.read()
except timeout:
print "Had a timeout!"
end = time.time()
print "Timeout 2.5 time: ", end-start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment