From c3015beb70004a76a3bc92c8eab6b85940f3bb9d Mon Sep 17 00:00:00 2001 From: poolitzer Date: Sun, 27 Jul 2025 16:02:39 +0200 Subject: [PATCH 01/11] [Fix] remove explicitly setting max_keepalive_connections --- src/telegram/request/_httpxrequest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/telegram/request/_httpxrequest.py b/src/telegram/request/_httpxrequest.py index bb35501f178..ecda82a0704 100644 --- a/src/telegram/request/_httpxrequest.py +++ b/src/telegram/request/_httpxrequest.py @@ -49,6 +49,10 @@ class HTTPXRequest(BaseRequest): Args: connection_pool_size (:obj:`int`, optional): Number of connections to keep in the connection pool. Defaults to ``1``. + + .. versionchanged:: NEXT.VERSION + Stopped applying to :paramref:`~httpx.Limits.max_keepalive_connections`. + Now only applys to :paramref:`~httpx.Limits.max_connections`. read_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a response from Telegram's server. This value is used unless a different value is passed to :meth:`do_request`. @@ -158,7 +162,6 @@ def __init__( ) limits = httpx.Limits( max_connections=connection_pool_size, - max_keepalive_connections=connection_pool_size, ) if http_version not in ("1.1", "2", "2.0"): From 9b20550ed1a39ad663b140a299abb6a349dbdbbe Mon Sep 17 00:00:00 2001 From: poolitzer Date: Sun, 27 Jul 2025 16:14:56 +0200 Subject: [PATCH 02/11] [Fix] Increase default maximum number of connections --- src/telegram/request/_httpxrequest.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/telegram/request/_httpxrequest.py b/src/telegram/request/_httpxrequest.py index ecda82a0704..58c84bb7f69 100644 --- a/src/telegram/request/_httpxrequest.py +++ b/src/telegram/request/_httpxrequest.py @@ -51,8 +51,10 @@ class HTTPXRequest(BaseRequest): connection pool. Defaults to ``1``. .. versionchanged:: NEXT.VERSION - Stopped applying to :paramref:`~httpx.Limits.max_keepalive_connections`. - Now only applys to :paramref:`~httpx.Limits.max_connections`. + Set the default to ``256``. + Stopped applying to ``httpx.Limits.max_keepalive_connections``. Now only applys to + ``httpx.Limits.max_connections``. See `Resource Limits + `_ read_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a response from Telegram's server. This value is used unless a different value is passed to :meth:`do_request`. @@ -141,7 +143,7 @@ class HTTPXRequest(BaseRequest): def __init__( self, - connection_pool_size: int = 1, + connection_pool_size: int = 256, read_timeout: Optional[float] = 5.0, write_timeout: Optional[float] = 5.0, connect_timeout: Optional[float] = 5.0, From 27c3b7ef3222c7a11e2834f8a9391c27cbf01cca Mon Sep 17 00:00:00 2001 From: poolitzer Date: Sun, 27 Jul 2025 18:25:32 +0200 Subject: [PATCH 03/11] Fix: Tests no longer fail --- tests/ext/test_applicationbuilder.py | 6 ++---- tests/request/test_request.py | 8 ++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/ext/test_applicationbuilder.py b/tests/ext/test_applicationbuilder.py index bfbce15dd93..47a766c0b68 100644 --- a/tests/ext/test_applicationbuilder.py +++ b/tests/ext/test_applicationbuilder.py @@ -150,9 +150,7 @@ class Client: assert app.bot.local_mode is False get_updates_client = app.bot._request[0]._client - assert get_updates_client.limits == httpx.Limits( - max_connections=1, max_keepalive_connections=1 - ) + assert get_updates_client.limits == httpx.Limits(max_connections=1) assert get_updates_client.proxy is None assert get_updates_client.timeout == httpx.Timeout( connect=5.0, read=5.0, write=5.0, pool=1.0 @@ -395,7 +393,7 @@ def init_httpx_request(self_, *args, **kwargs): client = app.bot.request._client assert client.timeout == httpx.Timeout(pool=3, connect=2, read=4, write=5) - assert client.limits == httpx.Limits(max_connections=1, max_keepalive_connections=1) + assert client.limits == httpx.Limits(max_connections=1) assert client.proxy == "proxy" assert client.http1 is True assert client.http2 is False diff --git a/tests/request/test_request.py b/tests/request/test_request.py index 0ebfe73532f..47b677df298 100644 --- a/tests/request/test_request.py +++ b/tests/request/test_request.py @@ -438,9 +438,7 @@ class Client: request = HTTPXRequest() assert request._client.timeout == httpx.Timeout(connect=5.0, read=5.0, write=5.0, pool=1.0) assert request._client.proxy is None - assert request._client.limits == httpx.Limits( - max_connections=1, max_keepalive_connections=1 - ) + assert request._client.limits == httpx.Limits(max_connections=1) assert request._client.http1 is True assert not request._client.http2 @@ -453,9 +451,7 @@ class Client: pool_timeout=46, ) assert request._client.proxy == "proxy" - assert request._client.limits == httpx.Limits( - max_connections=42, max_keepalive_connections=42 - ) + assert request._client.limits == httpx.Limits(max_connections=42) assert request._client.timeout == httpx.Timeout(connect=43, read=44, write=45, pool=46) async def test_multiple_inits_and_shutdowns(self, monkeypatch): From 47e5071da6f2eaec71c0fc05a3f9050b3d6ef473 Mon Sep 17 00:00:00 2001 From: Poolitzer <25934244+Poolitzer@users.noreply.github.com> Date: Sun, 27 Jul 2025 16:26:40 +0000 Subject: [PATCH 04/11] Add chango fragment for PR #4882 --- changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml diff --git a/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml b/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml new file mode 100644 index 00000000000..e1052df63ae --- /dev/null +++ b/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml @@ -0,0 +1,5 @@ +other = "Httpx timeout improvements" +[[pull_requests]] +uid = "4882" +author_uid = "Poolitzer" +closes_threads = [] From 1986aa04cf455c8f033c7a7de26b832dcbe052e5 Mon Sep 17 00:00:00 2001 From: poolitzer Date: Sun, 27 Jul 2025 22:12:50 +0200 Subject: [PATCH 05/11] Fix: Missed some tests --- tests/ext/test_applicationbuilder.py | 4 ++-- tests/request/test_request.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ext/test_applicationbuilder.py b/tests/ext/test_applicationbuilder.py index 47a766c0b68..af1e5d79fca 100644 --- a/tests/ext/test_applicationbuilder.py +++ b/tests/ext/test_applicationbuilder.py @@ -159,7 +159,7 @@ class Client: assert not get_updates_client.http2 client = app.bot.request._client - assert client.limits == httpx.Limits(max_connections=256, max_keepalive_connections=256) + assert client.limits == httpx.Limits(max_connections=256) assert client.proxy is None assert client.timeout == httpx.Timeout(connect=5.0, read=5.0, write=5.0, pool=1.0) assert client.http1 is True @@ -414,7 +414,7 @@ def init_httpx_request(self_, *args, **kwargs): client = app.bot._request[0]._client assert client.timeout == httpx.Timeout(pool=3, connect=2, read=4, write=5) - assert client.limits == httpx.Limits(max_connections=1, max_keepalive_connections=1) + assert client.limits == httpx.Limits(max_connections=1) assert client.proxy == "get_updates_proxy" assert client.http1 is True assert client.http2 is False diff --git a/tests/request/test_request.py b/tests/request/test_request.py index 47b677df298..7917669a0b7 100644 --- a/tests/request/test_request.py +++ b/tests/request/test_request.py @@ -438,7 +438,7 @@ class Client: request = HTTPXRequest() assert request._client.timeout == httpx.Timeout(connect=5.0, read=5.0, write=5.0, pool=1.0) assert request._client.proxy is None - assert request._client.limits == httpx.Limits(max_connections=1) + assert request._client.limits == httpx.Limits(max_connections=256) assert request._client.http1 is True assert not request._client.http2 From f1b8d65d9cabac37e5873f077ec64c3a55ef2a6a Mon Sep 17 00:00:00 2001 From: poolitzer Date: Sun, 27 Jul 2025 22:21:33 +0200 Subject: [PATCH 06/11] Feat: Better explanation of the docstring, and forgot to update the old 1 --- changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml | 2 +- src/telegram/request/_httpxrequest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml b/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml index e1052df63ae..7dac518959f 100644 --- a/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml +++ b/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml @@ -1,4 +1,4 @@ -other = "Httpx timeout improvements" +other = "Default httpx max_connections/pool size set to 256, and dropping setting max_keepalive_connections to the same amount. If you manually build the httpx request, be aware that this also applies to you. If you want your own limits, you can set them via httpx_kwargs, as explained in https://www.python-httpx.org/advanced/resource-limits/" [[pull_requests]] uid = "4882" author_uid = "Poolitzer" diff --git a/src/telegram/request/_httpxrequest.py b/src/telegram/request/_httpxrequest.py index 58c84bb7f69..4a61dbb8486 100644 --- a/src/telegram/request/_httpxrequest.py +++ b/src/telegram/request/_httpxrequest.py @@ -48,7 +48,7 @@ class HTTPXRequest(BaseRequest): Args: connection_pool_size (:obj:`int`, optional): Number of connections to keep in the - connection pool. Defaults to ``1``. + connection pool. Defaults to ``256``. .. versionchanged:: NEXT.VERSION Set the default to ``256``. From 895e0301b42b7bc41c448fd9315a7a1a446a0318 Mon Sep 17 00:00:00 2001 From: Poolitzer Date: Thu, 31 Jul 2025 17:57:41 +0200 Subject: [PATCH 07/11] Bad plural by me Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com> --- src/telegram/request/_httpxrequest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/telegram/request/_httpxrequest.py b/src/telegram/request/_httpxrequest.py index 4a61dbb8486..84682b41492 100644 --- a/src/telegram/request/_httpxrequest.py +++ b/src/telegram/request/_httpxrequest.py @@ -52,7 +52,7 @@ class HTTPXRequest(BaseRequest): .. versionchanged:: NEXT.VERSION Set the default to ``256``. - Stopped applying to ``httpx.Limits.max_keepalive_connections``. Now only applys to + Stopped applying to ``httpx.Limits.max_keepalive_connections``. Now only applies to ``httpx.Limits.max_connections``. See `Resource Limits `_ read_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum From a2538aaeaa79d0bcd48e8f33e24789bd557349c9 Mon Sep 17 00:00:00 2001 From: poolitzer Date: Thu, 31 Jul 2025 17:58:55 +0200 Subject: [PATCH 08/11] Fix: Explain reason behind changes --- changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml b/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml index 7dac518959f..4bf438a7ced 100644 --- a/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml +++ b/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml @@ -1,4 +1,4 @@ -other = "Default httpx max_connections/pool size set to 256, and dropping setting max_keepalive_connections to the same amount. If you manually build the httpx request, be aware that this also applies to you. If you want your own limits, you can set them via httpx_kwargs, as explained in https://www.python-httpx.org/advanced/resource-limits/" +other = "Default httpx max_connections/pool size set to 256 to allow more requests by default, and dropping setting max_keepalive_connections to the same amount (so bigger pools don't have a lot of unused alive connections). If you manually build the httpx request, be aware that this also applies to you. If you want your own limits, you can set them via httpx_kwargs, as explained in https://www.python-httpx.org/advanced/resource-limits/" [[pull_requests]] uid = "4882" author_uid = "Poolitzer" From 76f094355777f3c88eac20c0bef29a161636f8eb Mon Sep 17 00:00:00 2001 From: poolitzer Date: Thu, 31 Jul 2025 18:03:17 +0200 Subject: [PATCH 09/11] Fix: Forgot bot.py updates instance --- src/telegram/_bot.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/telegram/_bot.py b/src/telegram/_bot.py index c5ea0a7b182..d73280ff52f 100644 --- a/src/telegram/_bot.py +++ b/src/telegram/_bot.py @@ -339,7 +339,11 @@ def __init__( self._initialized: bool = False self._request: tuple[BaseRequest, BaseRequest] = ( - HTTPXRequest() if get_updates_request is None else get_updates_request, + ( + HTTPXRequest(connection_pool_size=1) + if get_updates_request is None + else get_updates_request + ), HTTPXRequest() if request is None else request, ) From d1dc7dd6510575590d8accd3b6953267ae6422f3 Mon Sep 17 00:00:00 2001 From: Poolitzer Date: Thu, 31 Jul 2025 20:22:43 +0200 Subject: [PATCH 10/11] adding hinrichs formulation Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com> --- changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml b/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml index 4bf438a7ced..6ed71524c8c 100644 --- a/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml +++ b/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml @@ -1,4 +1,9 @@ -other = "Default httpx max_connections/pool size set to 256 to allow more requests by default, and dropping setting max_keepalive_connections to the same amount (so bigger pools don't have a lot of unused alive connections). If you manually build the httpx request, be aware that this also applies to you. If you want your own limits, you can set them via httpx_kwargs, as explained in https://www.python-httpx.org/advanced/resource-limits/" +other = """ +Set the default connection pool size for ``HTTPXRequest`` to 256 to allow more concurrent requests by default. Drop the ``httpx`` parameter `max_keepalive_connections`. This way, the ``httpx`` default of 20 is used, leading to a smaller number of idle connections in large connection pools. + +.. hint: + If you manually build the ``HTTPXRequest`` objects, please be aware that these changes also applies to you. Kindly double check your settings. To specify custom limits, you can set them via the parameter ``httpx_kwargs`` of ``HTTPXRequest``. See also `the httpx documentation `__ for more details on these settings." +""" [[pull_requests]] uid = "4882" author_uid = "Poolitzer" From 429034eb8767546bcb304e174d35b720b8e35eb6 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Thu, 31 Jul 2025 20:45:43 +0200 Subject: [PATCH 11/11] small syntax fixes my bad, pool, mea culpa :D --- changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml b/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml index 6ed71524c8c..f47875d9dc3 100644 --- a/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml +++ b/changes/unreleased/4882.JpgQAHHnCponMKStbC4JsG.toml @@ -1,7 +1,7 @@ other = """ -Set the default connection pool size for ``HTTPXRequest`` to 256 to allow more concurrent requests by default. Drop the ``httpx`` parameter `max_keepalive_connections`. This way, the ``httpx`` default of 20 is used, leading to a smaller number of idle connections in large connection pools. +Set the default connection pool size for ``HTTPXRequest`` to 256 to allow more concurrent requests by default. Drop the ``httpx`` parameter ``max_keepalive_connections``. This way, the ``httpx`` default of 20 is used, leading to a smaller number of idle connections in large connection pools. -.. hint: +.. hint:: If you manually build the ``HTTPXRequest`` objects, please be aware that these changes also applies to you. Kindly double check your settings. To specify custom limits, you can set them via the parameter ``httpx_kwargs`` of ``HTTPXRequest``. See also `the httpx documentation `__ for more details on these settings." """ [[pull_requests]] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy