Skip to content

Instantly share code, notes, and snippets.

@vegitron
Created January 5, 2017 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vegitron/4ee269b6492ff80d350e108363689d5c to your computer and use it in GitHub Desktop.
Save vegitron/4ee269b6492ff80d350e108363689d5c to your computer and use it in GitHub Desktop.
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