Skip to content

Commit ebec945

Browse files
[PR #8681/30a3d0ef backport][3.10] Improve performance of starting request handlers with Python 3.12+ (#8725)
Co-authored-by: J. Nick Koston <nick@koston.org>
1 parent 78d45e7 commit ebec945

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

CHANGES/8681.misc.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Improved performance of starting request handlers with Python 3.12+ -- by :user:`bdraco`.
2+
3+
This change is a followup to :issue:`8661` to make the same optimization for Python 3.12+ where the request is connected.

aiohttp/web_protocol.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,16 @@ def connection_made(self, transport: asyncio.BaseTransport) -> None:
292292
if self._tcp_keepalive:
293293
tcp_keepalive(real_transport)
294294

295-
self._task_handler = self._loop.create_task(self.start())
296295
assert self._manager is not None
297296
self._manager.connection_made(self, real_transport)
298297

298+
loop = self._loop
299+
if sys.version_info >= (3, 12):
300+
task = asyncio.Task(self.start(), loop=loop, eager_start=True)
301+
else:
302+
task = loop.create_task(self.start())
303+
self._task_handler = task
304+
299305
def connection_lost(self, exc: Optional[BaseException]) -> None:
300306
if self._manager is None:
301307
return
@@ -494,7 +500,7 @@ async def start(self) -> None:
494500
keep_alive(True) specified.
495501
"""
496502
loop = self._loop
497-
handler = self._task_handler
503+
handler = asyncio.current_task(loop)
498504
assert handler is not None
499505
manager = self._manager
500506
assert manager is not None

0 commit comments

Comments
 (0)