Skip to content

Instantly share code, notes, and snippets.

@mvschaik
Created November 22, 2015 16:48
Show Gist options
  • Save mvschaik/fc66f14fb903dc2f0454 to your computer and use it in GitHub Desktop.
Save mvschaik/fc66f14fb903dc2f0454 to your computer and use it in GitHub Desktop.
Testing timeouts of AsyncHTTPClient
Code: 599
Req time: 2.00384807587
Timing info
{}
--------------------
Code: 599
Req time: 5.00563097
Timing info
{}
--------------------
Code: 200
Req time: 1.54284501076
Timing info
{'connect': 0.105714,
'namelookup': 4e-05,
'pretransfer': 0.238591,
'queue': 5.0056469440460205,
'redirect': 0.0,
'starttransfer': 1.5395889999999999,
'total': 1.540745}
--------------------
from tornado.httpclient import AsyncHTTPClient
from tornado.ioloop import IOLoop
from pprint import pprint
AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
def completed(resp):
print("Code: %s" % resp.code)
print("Req time: %s" % resp.request_time)
print("Timing info")
pprint(resp.time_info)
print("-" * 20)
def main():
client = AsyncHTTPClient(max_clients=1, defaults=dict(request_timeout=2.0))
client.fetch('https://httpbin.org/delay/3', callback=completed)
client.fetch('https://httpbin.org/delay/3', callback=completed)
client.fetch('https://httpbin.org/delay/1', callback=completed)
IOLoop.current().start()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment