Skip to content

Commit 978ed74

Browse files
[PR #9406/24b0e6f backport][3.10] Add __slots__ to timer helpers (#9411)
Co-authored-by: Sam Bull <[email protected]>
1 parent e1320b7 commit 978ed74

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGES/9406.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reduced memory required for timer objects created during the client request lifecycle -- by :user:`bdraco`.

aiohttp/helpers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ def calculate_timeout_when(
617617
class TimeoutHandle:
618618
"""Timeout handle"""
619619

620+
__slots__ = ("_timeout", "_loop", "_ceil_threshold", "_callbacks")
621+
620622
def __init__(
621623
self,
622624
loop: asyncio.AbstractEventLoop,
@@ -665,11 +667,17 @@ def __call__(self) -> None:
665667

666668

667669
class BaseTimerContext(ContextManager["BaseTimerContext"]):
670+
671+
__slots__ = ()
672+
668673
def assert_timeout(self) -> None:
669674
"""Raise TimeoutError if timeout has been exceeded."""
670675

671676

672677
class TimerNoop(BaseTimerContext):
678+
679+
__slots__ = ()
680+
673681
def __enter__(self) -> BaseTimerContext:
674682
return self
675683

@@ -685,6 +693,8 @@ def __exit__(
685693
class TimerContext(BaseTimerContext):
686694
"""Low resolution timeout context manager"""
687695

696+
__slots__ = ("_loop", "_tasks", "_cancelled", "_cancelling")
697+
688698
def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
689699
self._loop = loop
690700
self._tasks: List[asyncio.Task[Any]] = []

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,8 @@ skip = "pp*"
8282
[tool.codespell]
8383
skip = '.git,*.pdf,*.svg,Makefile,CONTRIBUTORS.txt,venvs,_build'
8484
ignore-words-list = 'te'
85+
86+
[tool.slotscheck]
87+
# TODO(3.13): Remove aiohttp.helpers once https://github.com/python/cpython/pull/106771
88+
# is available in all supported cpython versions
89+
exclude-modules = "(^aiohttp\\.helpers)"

0 commit comments

Comments
 (0)