Donovan
Donovan

Reputation: 816

How can I set a timeout on a Tornado HTTP request?

I am using the Tornado async HTTP client. I want to raise an exception if the request takes more than X milliseconds. How can I achieve this?

Upvotes: 0

Views: 1053

Answers (2)

pragman
pragman

Reputation: 1644

from the Tornado docs:

http://www.tornadoweb.org/en/stable/httpclient.html#request-objects

Use these named parameters in tornado.httpclient.HTTPRequest or in AsyncHTTPClient.fetch

connect_timeout (float) – Timeout for initial connection in seconds

request_timeout (float) – Timeout for entire request in seconds

Since they are floats, you should be able to specify the timeout in milliseconds, e.g. .1 will be 100 milliseconds

Upvotes: 1

Ben Darnell
Ben Darnell

Reputation: 22134

Use the request_timeout argument, which defaults to 20 seconds (floating point numbers are accepted, so you can use e.g. 0.1 for 100ms).

Upvotes: 3

Related Questions