简体   繁体   中英

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?

使用request_timeout参数,默认为20秒(接受浮点数,因此您可以在100ms内使用例如0.1)。

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, eg .1 will be 100 milliseconds

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM