[issue19524] ResourceWarning when urlopen() forgets the HTTPConnection object

Martin Panter report at bugs.python.org
Fri Dec 6 13:50:08 CET 2013


Martin Panter added the comment:

Here are two patches: a test case, and a fix for my issue. They were done against an installed version of Python 3.3.3.

I’m not entirely happy with the fix because it is accessing the private HTTPConnection.sock attribute from the urllib.request module, which seems a bit hacky. Other ideas would be to let HTTPConnection grow a new public method (or just a flag?) for cleaning itself up while leaving the response object still open. Or some kind of wrapper to augment the HTTPResponse.close() method to explicitly close the connection as well, like I originally mentioned.

Also my test case borrows some classes from the “test_urllib” module into the “test_urllib2”. This is the first time I’ve looked closely at the Python test suite; maybe there is a better to do that as well.

A bonus from my fix: it looks like it resolves a couple warnings running “test_urllib2net”.

----------
keywords: +patch
Added file: http://bugs.python.org/file33004/urllib-close-test.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19524>
_______________________________________


More information about the Python-bugs-list mailing list