Skip to content

Commit 7e9a688

Browse files
author
kevin
committed
refactor: add explicit parameters to Recognition API
1 parent 309cdf6 commit 7e9a688

3 files changed

Lines changed: 4 additions & 21 deletions

File tree

‎dashscope/api_entities/aio_session.py‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
import aiohttp
1717
import certifi
1818

19-
from dashscope.common.constants import (
20-
DEFAULT_CONNECTION_POOL_IDLE_TIMEOUT_SECONDS,
21-
)
2219
from dashscope.common.logging import logger
2320

2421
_shared_ssl_context: Optional[ssl.SSLContext] = None
@@ -41,8 +38,7 @@ async def get_shared_aio_session() -> aiohttp.ClientSession:
4138
4239
The session is lazily created on first use and reused for all
4340
subsequent calls on the same event loop. Connection pooling (keep-alive)
44-
is handled by the underlying TCPConnector with idle timeout configured
45-
to close stale connections.
41+
is handled by the underlying TCPConnector.
4642
"""
4743
loop = asyncio.get_running_loop()
4844

@@ -51,10 +47,7 @@ async def get_shared_aio_session() -> aiohttp.ClientSession:
5147
if session is not None and not session.closed:
5248
return session
5349

54-
connector = aiohttp.TCPConnector(
55-
ssl=get_ssl_context(),
56-
keepalive_timeout=DEFAULT_CONNECTION_POOL_IDLE_TIMEOUT_SECONDS,
57-
)
50+
connector = aiohttp.TCPConnector(ssl=get_ssl_context())
5851
session = aiohttp.ClientSession(connector=connector, trust_env=True)
5952

6053
_aio_sessions[loop] = session

‎dashscope/api_entities/http_request.py‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import aiohttp
1010
import requests
11-
from requests.adapters import HTTPAdapter
1211

1312
from dashscope.api_entities.aio_session import (
1413
get_shared_aio_session,
@@ -40,21 +39,13 @@ def _get_shared_sync_session() -> requests.Session:
4039
"""Return a shared requests.Session for connection pooling.
4140
4241
The session is created lazily and reused for the process lifetime;
43-
it is never closed explicitly. Connection pool is configured with
44-
pool size limits to control concurrent connections.
42+
it is never closed explicitly.
4543
"""
4644
global _shared_sync_session
4745
if _shared_sync_session is None:
4846
with _shared_sync_session_lock:
4947
if _shared_sync_session is None:
5048
_shared_sync_session = requests.Session()
51-
# Configure connection pool size
52-
adapter = HTTPAdapter(
53-
pool_connections=10,
54-
pool_maxsize=10,
55-
)
56-
_shared_sync_session.mount("http://", adapter)
57-
_shared_sync_session.mount("https://", adapter)
5849
return _shared_sync_session
5950

6051

‎dashscope/common/constants.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"api_key",
1818
)
1919

20-
DEFAULT_REQUEST_TIMEOUT_SECONDS = 120
21-
DEFAULT_CONNECTION_POOL_IDLE_TIMEOUT_SECONDS = 120
20+
DEFAULT_REQUEST_TIMEOUT_SECONDS = 300
2221
REQUEST_TIMEOUT_KEYWORD = "request_timeout"
2322
SERVICE_API_PATH = "services"
2423
DASHSCOPE_LOGGING_LEVEL_ENV = "DASHSCOPE_LOGGING_LEVEL"

0 commit comments

Comments
 (0)