New submission from STINNER Victor <victor.stin...@haypocalc.com>: test_urllibnet.py and test_urllibnet2.py emit ResourceWarning: ============== $ ./python Lib/test/test_urllibnet.py testURLread (__main__.URLTimeoutTest) ... ok test_bad_address (__main__.urlopenNetworkTests) ... ok test_basic (__main__.urlopenNetworkTests) ... ok test_fileno (__main__.urlopenNetworkTests) ... ok test_getcode (__main__.urlopenNetworkTests) ... /home/haypo/prog/GIT/py3k/Lib/socket.py:333: ResourceWarning: unclosed <socket.socket object, fd=3, family=2, type=1, proto=6> self._sock = None ok test_geturl (__main__.urlopenNetworkTests) ... ok test_info (__main__.urlopenNetworkTests) ... ok test_readlines (__main__.urlopenNetworkTests) ... ok test_basic (__main__.urlretrieveNetworkTests) ... /home/haypo/prog/GIT/py3k/Lib/socket.py:333: ResourceWarning: unclosed <socket.socket object, fd=3, family=2, type=2049, proto=6> self._sock = None ok test_data_header (__main__.urlretrieveNetworkTests) ... /home/haypo/prog/GIT/py3k/Lib/socket.py:333: ResourceWarning: unclosed <socket.socket object, fd=3, family=2, type=2049, proto=6> self._sock = None ok test_header (__main__.urlretrieveNetworkTests) ... /home/haypo/prog/GIT/py3k/Lib/socket.py:333: ResourceWarning: unclosed <socket.socket object, fd=3, family=2, type=2049, proto=6> self._sock = None ok test_specified_path (__main__.urlretrieveNetworkTests) ... /home/haypo/prog/GIT/py3k/Lib/socket.py:333: ResourceWarning: unclosed <socket.socket object, fd=3, family=2, type=2049, proto=6> self._sock = None ok
---------------------------------------------------------------------- Ran 12 tests in 17.473s ============== It looks like these warning are real bugs: the socket is not closed explicitly by urllib. Nadeem Vawda suggests a first fix: diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -2151,7 +2151,9 @@ conn = self.ftp.ntransfercmd(cmd) self.busy = 1 # Pass back both a suitably decorated object and a retrieval length - return (addclosehook(conn[0].makefile('rb'), self.endtransfer), conn[1]) + fp = addclosehook(conn[0].makefile('rb'), self.endtransfer) + conn[0].close() + return (fp, conn[1]) def endtransfer(self): if not self.busy: return ---------- components: Library (Lib) messages: 125944 nosy: haypo, nvawda, orsenthil priority: normal severity: normal status: open title: urllib: socket is not closed explicitly versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue10883> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com