New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File leak in ElementTree.iterparse() #69874
Comments
ElementTree.iterparse() can leak internally open file in case of error. Proposed patch fixes the leak. |
What’s the point of the catch_warnings() and filterwarnings() calls in the tests? They don’t seem to be doing much; I think the CleanContext manager is already enabling warnings. Perhaps you could call simplefilter("error", ResourceWarning) instead. Also I’m not enthusiastic about the iterparse() API when passing a file name. If it has to stay, maybe there should be an explicit way to clean it up without exhausting the iterator, like a generator.close() method. |
Warning is emitted in destructor, and exceptions in destructors are ignored. Hence turning it into error makes the test passed. Tests were not correct, here is fixed patch. Yes, CleanContext does the work. But depending on it looks fragile. CleanContext can be removed after getting rid of all deprecated methods. I agree that we have to add the close() method to iterparse object. But this is new feature and separate issue. |
Patch 2 looks good. I like the new version of the tests better. |
New changeset 6e23777948f3 by Serhiy Storchaka in branch '3.4': New changeset 267d04459ba3 by Serhiy Storchaka in branch '3.5': New changeset d841205776fe by Serhiy Storchaka in branch 'default': New changeset 09a8ac75b351 by Serhiy Storchaka in branch '2.7': |
Thank you for your review Martin. Opened bpo-25707 for adding the close method. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: