Skip to content

Commit

Permalink
[PR #8681/30a3d0ef backport][3.10] Improve performance of starting re…
Browse files Browse the repository at this point in the history
…quest handlers with Python 3.12+ (#8725)

Co-authored-by: J. Nick Koston <nick@koston.org>
  • Loading branch information
patchback[bot] and bdraco authored Aug 17, 2024
1 parent 78d45e7 commit ebec945
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES/8681.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Improved performance of starting request handlers with Python 3.12+ -- by :user:`bdraco`.

This change is a followup to :issue:`8661` to make the same optimization for Python 3.12+ where the request is connected.
10 changes: 8 additions & 2 deletions aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,16 @@ def connection_made(self, transport: asyncio.BaseTransport) -> None:
if self._tcp_keepalive:
tcp_keepalive(real_transport)

self._task_handler = self._loop.create_task(self.start())
assert self._manager is not None
self._manager.connection_made(self, real_transport)

loop = self._loop
if sys.version_info >= (3, 12):
task = asyncio.Task(self.start(), loop=loop, eager_start=True)
else:
task = loop.create_task(self.start())
self._task_handler = task

def connection_lost(self, exc: Optional[BaseException]) -> None:
if self._manager is None:
return
Expand Down Expand Up @@ -494,7 +500,7 @@ async def start(self) -> None:
keep_alive(True) specified.
"""
loop = self._loop
handler = self._task_handler
handler = asyncio.current_task(loop)
assert handler is not None
manager = self._manager
assert manager is not None
Expand Down

0 comments on commit ebec945

Please sign in to comment.