[issue11563] test_urllibnet is triggering a ResourceWarning
Jeff McNeil
report at bugs.python.org
Thu Mar 17 19:30:50 CET 2011
Jeff McNeil <jeff at jmcneil.net> added the comment:
So, it turned out to be more complicated than that. The HTTPConnection object returns an HTTPResponse, but never closes the underlying socket after calling makesock.
Since persistent connections aren't supported, nothing actually closes the socket itself, it's just set to None. Explicitly calling a close turns out not to be correct either.
I went down the same path as AbstractHTTPHandler and added a Connection: close header. That ensures that the remote host will close the underlying connection (more importantly, setting the HTTP Response object's will_close to True). That ensures HTTPConnection performs in a "fire and forget" mode, causing everything to close out as it should.
I contemplated changing urlretrieve to use build_opener as urlopen does, but I figure that would have been done by now if it was a trivial operation. I'd be happy to take a whack at it if it's just a matter of getting around to it.
----------
keywords: +patch
Added file: http://bugs.python.org/file21273/11562.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11563>
_______________________________________
More information about the Python-bugs-list
mailing list