Skip to content

Create an event loop before starting the app on Python 3.14 - #78

Draft
aiolibsbot wants to merge 1 commit into
sanitizers:masterfrom
aiolibsbot:koan/python-314-event-loop
Draft

aiolibsbot wants to merge 1 commit into
sanitizers:masterfrom
aiolibsbot:koan/python-314-event-loop

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented Sep 17, 2026 •

Copy link
Copy Markdown

What

Create an event loop at the entry point so the app boots on Python 3.14.

Why

Reproduced #71 locally on CPython 3.14.5. The traceback bottoms out in
anyio v1.4 (_backends/_asyncio.py:104), which starts the app with
asyncio.get_event_loop() and relies on it implicitly creating a loop when
the main thread has none. Python 3.14 removed that fallback, so it raises
RuntimeError: There is no current event loop in thread 'MainThread'.

octomachinery 0.3.11 declares anyio <2.0.0, so patchback cannot resolve
this by unpinning — the real fix lives upstream.

Good news from the investigation: that one call is the only 3.14 blocker.
With a loop present, the whole stack (anyio → aiohttp → octomachinery →
gidgethub) runs fine on 3.14.

How

One guarded statement in __main__.py doing what the interpreter used to do
for us. It leaves older Pythons untouched and stops being necessary once
octomachinery supports anyio v2+ — the NOTE block says so.

Testing

python -m patchback with throwaway App credentials, 2×2:

unpatched patched
3.14.5 RuntimeError: There is no current event loop gidgethub.BadRequest: Integration not found
3.13.13 gidgethub.BadRequest: Integration not found gidgethub.BadRequest: Integration not found

Integration not found is the server rejecting the dummy App ID — i.e. the
app booted, started serving and made a real authenticated API call. 3.14 now
matches 3.13; 3.13 is unchanged.

Repro:

$ python3.14 -Im venv .venv && .venv/bin/python -Im pip install -r requirements.txt
$ openssl genrsa -out key.pem 2048
$ GITHUB_APP_IDENTIFIER=1 GITHUB_PRIVATE_KEY="$(cat key.pem)" \
  GITHUB_WEBHOOK_SECRET=x .venv/bin/python -m patchback

No unit test: the anyio boot path needs the full dependency set plus App
credentials, which a plain pytest job cannot provide honestly.

Refs #71


Quality Report

Changes: 1 file changed, 12 insertions(+)

Code scan: clean

Tests: skipped

Branch hygiene: clean

Generated by Kōan

`anyio` v1 boots the app through `asyncio.get_event_loop()`, depending on it
to implicitly create a loop when the main thread has none. Python 3.14 removed
that fallback, so the call raises `RuntimeError: There is no current event
loop in thread 'MainThread'` and the app never starts.

`octomachinery` caps `anyio` below v2, so upgrading the dependency is not an
option here. Creating the loop at the entry point instead restores exactly the
behaviour the interpreter used to provide, leaves older Pythons unaffected and
becomes a no-op once `octomachinery` grows `anyio` v2+ support.

Verified by running `python -m patchback` under both interpreters: on 3.14 it
now gets all the way to authenticating against the GitHub API instead of dying
in `anyio`, and 3.13 behaves the same before and after.

Refs sanitizers#71

This branch has not been deployed

No deployments
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.

1 participant