mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #1561 from coder2020official/bugfixes
Aiohttp client session management improvements.
This commit is contained in:
commit
1943f659bc
@ -1,4 +1,4 @@
|
||||
pytest
|
||||
requests==2.20.0
|
||||
wheel==0.24.0
|
||||
aiohttp>=3.8.0,<3.9.0
|
||||
aiohttp>=3.8.0,<3.9.0
|
@ -19,21 +19,22 @@ session = None
|
||||
|
||||
FILE_URL = None
|
||||
|
||||
CONNECT_TIMEOUT = 15
|
||||
READ_TIMEOUT = 30
|
||||
|
||||
LONG_POLLING_TIMEOUT = 10 # Should be positive, short polling should be used for testing purposes only (https://core.telegram.org/bots/api#getupdates)
|
||||
REQUEST_TIMEOUT = 10
|
||||
REQUEST_TIMEOUT = None
|
||||
MAX_RETRIES = 3
|
||||
|
||||
REQUEST_LIMIT = 50
|
||||
|
||||
class SessionManager:
|
||||
def __init__(self) -> None:
|
||||
self.session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(limit=REQUEST_LIMIT))
|
||||
self.session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(
|
||||
limit=REQUEST_LIMIT
|
||||
))
|
||||
|
||||
|
||||
async def create_session(self):
|
||||
self.session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(limit=REQUEST_LIMIT))
|
||||
self.session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(
|
||||
limit=REQUEST_LIMIT
|
||||
))
|
||||
return self.session
|
||||
|
||||
async def get_session(self):
|
||||
@ -61,10 +62,11 @@ async def _process_request(token, url, method='get', params=None, files=None, re
|
||||
current_try +=1
|
||||
try:
|
||||
async with session.request(method=method, url=API_URL.format(token, url), data=params, timeout=timeout, proxy=proxy) as resp:
|
||||
got_result = True
|
||||
logger.debug("Request: method={0} url={1} params={2} files={3} request_timeout={4} current_try={5}".format(method, url, params, files, request_timeout, current_try).replace(token, token.split(':')[0] + ":{TOKEN}"))
|
||||
|
||||
json_result = await _check_result(url, resp)
|
||||
if json_result:
|
||||
got_result = True
|
||||
return json_result['result']
|
||||
except (ApiTelegramException,ApiInvalidJSONException, ApiHTTPException) as e:
|
||||
raise e
|
||||
|
Loading…
Reference in New Issue
Block a user