This error is because the timeout parameter set is not supported when tornado is used in python. Normally, the value of the timeout parameter should be an integer or a float, but in this case an unsupported value was passed in. May be another type or a value that cannot be converted to an integer or float.
To solve this error, you need to ensure that the value of the timeout parameter passed in is an integer or float. This can be ensured by adjusting code or configuration files. You can first check whether the value passed in the timeout parameter is legal. If it is not an integer or float, you can use functions such as int() or float() to convert it to a legal value.
Before you use the timeout parameter, you can also check whether the timeout parameter is legal. If not, set a default value or throw an exception.
Yes, here is a simple example:
import tornado.ioloop def handle_timeout(): print("timeout occurred") def start_timeout(timeout): if not isinstance(timeout, (int,float)): raise ValueError("timeout must be a number") tornado.ioloop.IOLoop.current().call_later(timeout, handle_timeout) try: start_timeout(10) # this will work start_timeout("10") # this will raise ValueError except ValueError as e: print(str(e))
In this example, we check whether the timeout parameter passed in is an integer or float. If not, a ValueError exception will be thrown.
Another way is to use the default value, such as
def start_timeout(timeout=10): if not isinstance(timeout, (int,float)): timeout = 10 tornado.ioloop.IOLoop.current().call_later(timeout, handle_timeout) start_timeout() # this will use the default timeout of 10s
Here, we use a default value of 10s. If the timeout parameter passed in is illegal, we use the default value.
The above is the detailed content of What's going on when tornado reports a TypeError (\'Unsupported timeout %r\' % timeout) error?. For more information, please follow other related articles on the PHP Chinese website!