Skip to content

gh-153534: Broaden _asyncio _call_soon fast path to safe BaseEventLoop subclasses#153535

Draft
KRRT7 wants to merge 1 commit into
python:mainfrom
KRRT7:kevin/asyncio-subclass-fastpath
Draft

gh-153534: Broaden _asyncio _call_soon fast path to safe BaseEventLoop subclasses#153535
KRRT7 wants to merge 1 commit into
python:mainfrom
KRRT7:kevin/asyncio-subclass-fastpath

Conversation

@KRRT7

@KRRT7 KRRT7 commented Jul 10, 2026

Copy link
Copy Markdown

Closes gh-153534.

This broadens _asyncio's internal call_soon() helper to use the private
_call_soon() fast path for safe subclasses of stdlib
asyncio.base_events.BaseEventLoop, not just exact built-in loop types.

The fast path now applies only when the loop:

  • is a stdlib BaseEventLoop subclass
  • does not define call_soon on the subclass type
  • does not shadow call_soon on the instance

Otherwise _asyncio falls back to the public call_soon() path.

This preserves behavior for custom loop behavior while expanding the
optimization to the common subclass-without-override case.

Notes

  • Implementation note:
    • the guard does not cache BaseEventLoop during _asyncio init because
      _asyncio is imported while asyncio.base_events is still initializing
      and that creates an import cycle

@bedevere-app

bedevere-app Bot commented Jul 10, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@KRRT7 KRRT7 changed the title Broaden _asyncio _call_soon fast path to safe BaseEventLoop subclasses gh-153534: Broaden _asyncio _call_soon fast path to safe BaseEventLoop subclasses Jul 10, 2026
@KRRT7 KRRT7 force-pushed the kevin/asyncio-subclass-fastpath branch from 3360616 to 2bb306d Compare July 11, 2026 02:10
@KRRT7 KRRT7 force-pushed the kevin/asyncio-subclass-fastpath branch from f06be0e to b2c13fc Compare July 11, 2026 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider broadening _asyncio _call_soon fast path beyond exact built-in loop types

1 participant