python / python/cpython

The event loop warns only on Windows 3.14+ if it isn't closed before garbage collection

Aperta
#141,262 5 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@johnslavik ci sta già lavorando.

Dal 20/7/2026.

3.13 3.14 3.15 3.16 stdlib topic-asyncio type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Bug description:

This program reports ResourceWarning: unclosed event loop <ProactorEventLoop running=False closed=False debug=False> only on Windows and only since 3.14:

import asyncio
asyncio.set_event_loop(loop := asyncio.new_event_loop())
loop.run_until_complete(asyncio.sleep(1))

Other platforms and versions in the 3.9-3.15 Linux-MacOS-Windows matrix don't do that.

See jobs.
I've reproduced this at main too.

Key things I'm investigating:

  • Is it mandatory to call .close() manually, if we don't use a runner?
    • If yes, why does only Windows 3.14+ proactor loop raise this warning, and loops on other platforms and versions do not?
    • If no (since most platforms and versions seemingly do not require this), why does the loop raise the warning?
  • In general, could and should the asyncio REPL use a runner?

I've found this while working on the asyncio REPL. This issue blocks me from completing #140287. Note that the asyncio REPL does call .stop(); it only doesn't call .close(). .stop() is not meant to stop the loop for good (the loop is re-entrant), .close() is irreversible and idempotent.

CPython versions tested on:

3.9, 3.10, 3.11, 3.12, 3.13, 3.14, 3.15, CPython main branch

Operating systems tested on:

Windows, macOS, Linux

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.