This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients pitrou, serhiy.storchaka, vstinner
Date 2016-03-21.16:07:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1458576446.66.0.754431143479.issue26603@psf.upfronthosting.co.za>
In-reply-to
Content
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".
History
Date User Action Args
2016-03-21 16:07:26vstinnersetrecipients: + vstinner, pitrou, serhiy.storchaka
2016-03-21 16:07:26vstinnersetmessageid: <1458576446.66.0.754431143479.issue26603@psf.upfronthosting.co.za>
2016-03-21 16:07:26vstinnerlinkissue26603 messages
2016-03-21 16:07:26vstinnercreate