Message262136
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". |
|
Date |
User |
Action |
Args |
2016-03-21 16:07:26 | vstinner | set | recipients:
+ vstinner, pitrou, serhiy.storchaka |
2016-03-21 16:07:26 | vstinner | set | messageid: <1458576446.66.0.754431143479.issue26603@psf.upfronthosting.co.za> |
2016-03-21 16:07:26 | vstinner | link | issue26603 messages |
2016-03-21 16:07:26 | vstinner | create | |
|