Repository navigation
The event loop warns only on Windows 3.14+ if it isn't closed before garbage collection #141262
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Nov 8, 2025 CC @ZeroIntensity labels:
stdlib,topic-asyncio,3.13,3.14,3.15Reacted by Peter Bierma- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes
on Nov 8, 2025 All of them should raise the warning, if not then it is a bug which should be fixed.
If yes, why does only Windows 3.14+ proactor loop raise this warning, and loops on other platforms and versions do not?
The implementation on Windows and on Unix is different. The Unix implementation is based on
BaseSelectorEventLoopwhich uses a "self pipe" which does:self._add_reader(self._ssock.fileno(), self._read_from_self)This line creates a reference cycle. It prevents the event loop to be deallocated by the GC.
The Windows implementation also uses a "self pipe" but with a different implementation which doesn't seem to suffer from the same reference cycle issue.
Reacted by Bartosz SławeckiThanks. I'll see what I can do.
This line creates a reference cycle. It prevents the event loop to be deallocated by the GC.
That's not the actual issue here though. The issue is that the code calls
asyncio.set_event_loopwhich stores the loop inside the policy object which is a module global so that global variable keeps the loop alive until the module is cleared.The code raises the warning if the
set_event_loopis removed.import asyncio loop = asyncio.new_event_loop() loop.run_until_complete(asyncio.sleep(1))
❯ ./python.exe main.py /Users/kumaraditya/work/cpython/Lib/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>
- added3.16new features, bugs and security fixesnew features, bugs and security fixes
on Jul 27, 2026
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsTodo
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: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:
.close()manually, if we don't 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