Jeff McNeil <j...@jmcneil.net> added the comment:

So, I've been meaning to get more into contributing back to Python and I found 
this one somewhat interesting.

As it turns out, even the following simple script raises the same warning:


[jeff@martian cpython]$ ./python -c 'import urllib.request; 
urllib.request.urlretrieve("http://www.python.org";)'
/home/jeff/cpython/Lib/socket.py:340: ResourceWarning: unclosed <socket.socket 
object, fd=3, family=2, type=1, proto=6>
  self._sock = None
[64388 refs]
[jeff@martian cpython]$ 

The close method of Socket.SocketIO simply sets the underlying socket object to 
None, which causes that warning.  Explicitly calling the close method on the 
underlying socket clears that up (and it's protected by that reference counter).

The _decref_socketios just drops the internal ref count and never actually 
closes -- it won't unless self.__closed is True. 

So, when self._sock is set to None, that error bubbles up. As SocketIO is the 
foundation used in socket.makefile, I think just adding that close call ought 
to be correct.

I can do the simple patch if you agree.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11563>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to