资源限制
¥Resource Limits
您可以使用以下方式控制连接池大小limits客户端上的关键字参数。它需要httpx.Limits定义:
¥You can control the connection pool size using the limits keyword
argument on the client. It takes instances of httpx.Limits which define:
max_keepalive_connections、允许的保持连接数,或None始终允许。(默认值 20)¥
max_keepalive_connections, number of allowable keep-alive connections, orNoneto always allow. (Defaults 20)max_connections、允许的最大连接数,或None无限制。(默认值 100)¥
max_connections, maximum number of allowable connections, orNonefor no limits. (Default 100)keepalive_expiry、空闲保持连接的时间限制(以秒为单位),或None无限制。(默认值 5)¥
keepalive_expiry, time limit on idle keep-alive connections in seconds, orNonefor no limits. (Default 5)
limits = httpx.Limits(max_keepalive_connections=5, max_connections=10)
client = httpx.Client(limits=limits)