Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __slots__ to timer helpers #9406

Merged
merged 6 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/9406.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduced memory required for timer objects created during the client request lifecycle -- by :user:`bdraco`.
10 changes: 10 additions & 0 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ def calculate_timeout_when(
class TimeoutHandle:
"""Timeout handle"""

__slots__ = ("_timeout", "_loop", "_ceil_threshold", "_callbacks")

def __init__(
self,
loop: asyncio.AbstractEventLoop,
Expand Down Expand Up @@ -644,11 +646,17 @@ def __call__(self) -> None:


class BaseTimerContext(ContextManager["BaseTimerContext"]):

__slots__ = ()

def assert_timeout(self) -> None:
"""Raise TimeoutError if timeout has been exceeded."""


class TimerNoop(BaseTimerContext):

__slots__ = ()

def __enter__(self) -> BaseTimerContext:
return self

Expand All @@ -664,6 +672,8 @@ def __exit__(
class TimerContext(BaseTimerContext):
"""Low resolution timeout context manager"""

__slots__ = ("_loop", "_tasks", "_cancelled", "_cancelling")

def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
self._loop = loop
self._tasks: List[asyncio.Task[Any]] = []
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ skip = "pp*"
[tool.codespell]
skip = '.git,*.pdf,*.svg,Makefile,CONTRIBUTORS.txt,venvs,_build'
ignore-words-list = 'te,assertIn'

[tool.slotscheck]
# Remove aiohttp.helkpers once https://github.com/python/cpython/pull/106771
bdraco marked this conversation as resolved.
Show resolved Hide resolved
# is available in all supported cpython versions
bdraco marked this conversation as resolved.
Show resolved Hide resolved
exclude-modules = "(^aiohttp\\.helpers)"