Skip to content

Commit

Permalink
Remove pool_timeout args from HTTPXRequest + pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibo-Joshi committed Jan 2, 2022
1 parent 4d19a16 commit e1b66bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
18 changes: 9 additions & 9 deletions telegram/request/_baserequest.py
Expand Up @@ -115,7 +115,7 @@ async def shutdown(self) -> None:

async def post(
self,
request_data: RequestData = None,
request_data: RequestData,
connect_timeout: float = None,
read_timeout: float = None,
write_timeout: float = None,
Expand All @@ -129,8 +129,8 @@ async def post(
Args:
request_data (:class:`telegram.request.RequestData`, optional): An object describing
any parameters and files to upload for the request.
request_data (:class:`telegram.request.RequestData`): An object containing
all information about target, parameters and files to upload for the request.
connect_timeout (:obj:`float`, optional): If passed, specifies the maximum amount of
time (in seconds) to wait for a connection attempt to a server to succeed instead
of the time specified during creating of this object.
Expand Down Expand Up @@ -198,7 +198,7 @@ async def retrieve(
async def _request_wrapper(
self,
method: str,
request_data: RequestData = None,
request_data: RequestData,
read_timeout: float = None,
connect_timeout: float = None,
write_timeout: float = None,
Expand All @@ -213,8 +213,8 @@ async def _request_wrapper(
Args:
method (:obj:`str`): HTTP method (i.e. 'POST', 'GET', etc.).
url (:obj:`str`): The request's URL.
request_data (:class:`telegram.request.RequestData`, optional): An object describing
any parameters and files to upload for the request.
request_data (:class:`telegram.request.RequestData`): An object containing
all information about target, parameters and files to upload for the request.
read_timeout: Timeout for waiting to server's response.
Returns:
Expand Down Expand Up @@ -303,7 +303,7 @@ def _parse_json_response(json_payload: bytes) -> JSONDict:
async def do_request(
self,
method: str,
request_data: RequestData = None,
request_data: RequestData,
connect_timeout: float = None,
read_timeout: float = None,
write_timeout: float = None,
Expand All @@ -317,8 +317,8 @@ async def do_request(
Args:
method (:obj:`str`): HTTP method (i.e. ``'POST'``, ``'GET'``, etc.).
request_data (:class:`telegram.request.RequestData`, optional): An object describing
any parameters and files to upload for the request.
request_data (:class:`telegram.request.RequestData`): An object containing
all information about target, parameters and files to upload for the request.
read_timeout (:obj:`float`, optional): If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the
connection pool).
Expand Down
16 changes: 2 additions & 14 deletions telegram/request/_httpxrequest.py
Expand Up @@ -67,10 +67,6 @@ class HTTPXRequest(BaseRequest):
write_timeout (:obj:`float`, optional): The maximum amount of time (in seconds) to wait for
a write operation to complete (in terms of a network socket; i.e. POSTing a request or
uploading a file).:obj:`None` will set an infinite timeout. Defaults to ``5.0``.
pool_timeout (:obj:`float`, optional): Timeout waiting for a connection object to become
available and returned from the connection pool. :obj:`None` will set an infinite
timeout. Defaults to ``1.0``.
"""

__slots__ = ('_client', '_connection_pool_size', '__pool_semaphore')
Expand All @@ -82,15 +78,13 @@ def __init__(
connect_timeout: Optional[float] = 5.0,
read_timeout: Optional[float] = 5.0,
write_timeout: Optional[float] = 5.0,
pool_timeout: Optional[float] = 1.0,
):
self.__pool_semaphore = asyncio.BoundedSemaphore(connection_pool_size)

timeout = httpx.Timeout(
connect=connect_timeout,
read=read_timeout,
write=write_timeout,
pool=pool_timeout,
)
self._connection_pool_size = connection_pool_size + 1
limits = httpx.Limits(
Expand Down Expand Up @@ -139,7 +133,7 @@ async def shutdown(self) -> None:
async def do_request(
self,
method: str,
request_data: RequestData = None,
request_data: RequestData,
connect_timeout: float = None,
read_timeout: float = None,
write_timeout: float = None,
Expand All @@ -153,7 +147,6 @@ async def do_request(
connect_timeout=connect_timeout,
read_timeout=read_timeout,
write_timeout=write_timeout,
pool_timeout=pool_timeout,
)

async with self.__pool_semaphore:
Expand All @@ -163,33 +156,28 @@ async def do_request(
connect_timeout=connect_timeout,
read_timeout=read_timeout,
write_timeout=write_timeout,
pool_timeout=pool_timeout,
)
return out

async def _do_request(
self,
method: str,
request_data: RequestData = None,
request_data: RequestData,
connect_timeout: float = None,
read_timeout: float = None,
write_timeout: float = None,
pool_timeout: float = None,
) -> Tuple[int, bytes]:
timeout = httpx.Timeout(
connect=self._client.timeout.connect,
read=self._client.timeout.read,
write=self._client.timeout.write,
pool=self._client.timeout.pool,
)
if read_timeout is not None:
timeout.read = read_timeout
if write_timeout is not None:
timeout.write = write_timeout
if connect_timeout is not None:
timeout.connect = connect_timeout
if pool_timeout is not None:
timeout.pool = pool_timeout

# TODO p0: On Linux, use setsockopt to properly set socket level keepalive.
# (socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 120)
Expand Down

0 comments on commit e1b66bd

Please sign in to comment.