New submission from STINNER Victor: Attached patch implements a finalizer for os.scandir() iterator type. The patch also calls the new PyErr_ResourceWarning() function to be able to display in the warning where the iterator was created (allocated) when tracemalloc is enabled.
While it makes sense to pass an "open" socket to the logger of the ResourceWarning warning for sockets (issue #26590), maybe we can close the ScandirIterator *before* calling the logger? Example: --- import os f = os.scandir('.') f = None --- Output: --- $ ./python -X tracemalloc -Wd example.py example.py:3: ResourceWarning: unclosed scandir iterator <posix.ScandirIterator object at 0x7f21cdb15280> f = None Object allocated at (most recent call first): File "example.py", lineno 2 f = os.scandir('.') --- See also the issue #26590 "socket destructor: implement finalizer". ---------- messages: 262136 nosy: haypo, pitrou, serhiy.storchaka priority: normal severity: normal status: open title: os.scandir: implement finalizer (for ResourceWarning) versions: Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26603> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com