You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The event loop warns only on Windows 3.14+ if it isn't closed before garbage collection #141262
This program reports ResourceWarning: unclosed event loop <ProactorEventLoop running=False closed=False debug=False> only on Windows and only since 3.14:
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
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.
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_loop which 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_loop is removed.
Activity
johnslavik commentedon Nov 8, 2025
CC @ZeroIntensity labels:
stdlib,topic-asyncio,3.13,3.14,3.15kumaraditya303 commentedon Nov 9, 2025
All of them should raise the warning, if not then it is a bug which should be fixed.
vstinner commentedon Nov 13, 2025
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.
johnslavik commentedon Nov 15, 2025
Thanks. I'll see what I can do.
kumaraditya303 commentedon Nov 16, 2025
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.