Title: Fix ResourceWarning in Lib/test/
Type: Stage:
Components: Tests Versions: Python 3.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, orsenthil, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2012-10-22 15:46 by berker.peksag, last changed 2012-10-23 06:15 by berker.peksag. This issue is now closed.

File name Uploaded Description Edit
resourcewarning_urllib_test.patch berker.peksag, 2012-10-22 15:46 review
resourcewarning_urllib_test_v2.patch berker.peksag, 2012-10-22 16:24 review
Messages (6)
msg173532 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2012-10-22 15:46
See the output:

test_file_notexists (test.test_urllib.urlopen_HttpTests) ... file:///tmp/tmpmlmjhf
/home/berker/hacking/cpython/Lib/test/ ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/tmpmlmjhf'>
msg173533 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-22 15:48
thanks for the bug-report/patch.
msg173536 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-22 16:04
You can use contextlib.closing() context manager (if urlopen() already does not return a context manager).
msg173539 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2012-10-22 16:24
Thanks for the suggestion, Serhiy.

Attached a new patch.
msg173572 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-23 00:09
Fixed in 478cda291bbc

Berker - 

     with urlopen(tmp_fileurl) as fobj:

is enough when using context manager as the fobj gets closed automatically at exiting of context.

msg173580 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2012-10-23 06:15
You are right, thanks Senthil.
Date User Action Args
2012-10-23 06:15:33berker.peksagsetmessages: + msg173580
2012-10-23 00:09:45orsenthilsetstatus: open -> closed
resolution: fixed
messages: + msg173572

versions: - Python 3.3
2012-10-22 16:24:53berker.peksagsetfiles: + resourcewarning_urllib_test_v2.patch

messages: + msg173539
2012-10-22 16:04:59serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg173536
2012-10-22 15:48:50orsenthilsetnosy: + orsenthil
messages: + msg173533
2012-10-22 15:46:00berker.peksagcreate