python / python/cpython

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

未關閉
#141,262 5 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

@johnslavik 已經在處理了。

開始於 2026年7月20日。

3.13 3.14 3.15 3.16 stdlib topic-asyncio type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。