Skip to content

Commit

Permalink
Improve performance of starting request handlers with Python 3.12+ (#…
Browse files Browse the repository at this point in the history
…8681)

(cherry picked from commit 30a3d0e)
  • Loading branch information
bdraco authored and patchback[bot] committed Aug 17, 2024
1 parent c6c36a6 commit f9d33db
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 f9d33db

Please sign in to comment.