All Products
Search
Document Center

Alibaba Cloud SDK:Configure a timeout period

Last Updated:Oct 13, 2025

In software development, you configure a timeout period to prevent a program from being blocked while waiting for a response. Without a timeout, your program might waste resources or even crash. If the timeout is too short, a task might be interrupted before it finishes, which can disrupt normal operations. Setting an appropriate timeout improves system stability and user experience. This topic describes how to configure timeouts for the Alibaba Cloud SDK for Python V2.0.

Timeout configuration

Note

The priority of timeout settings from highest to lowest is: RuntimeOptions settings, Config settings, and default configurations.

  • Use default settings. The default timeout period for connection requests is 5,000 milliseconds and the default timeout period for read requests is 10,000 milliseconds.

  • Configure the timeout for the current request using runtime parameters (RuntimeOptions).

    from alibabacloud_tea_util.models import RuntimeOptions
    
    # Takes effect on requests that use RuntimeOptions.
    runtimeOptions = RuntimeOptions(
        read_timeout=10000,  # Read timeout in milliseconds (ms)
        connect_timeout=5000  # Connection timeout in milliseconds (ms)
    )
    
  • Configure a global timeout using the Config class.

    from alibabacloud_tea_openapi.models import Config
    
    # The timeout settings take effect for all clients initialized with this Config.
    config = Config(
        read_timeout=10000,  # Read timeout in milliseconds (ms)
        connect_timeout=5000  # Connection timeout in milliseconds (ms)
    )