[issue10512] regrtest ResourceWarning - unclosed sockets and files

Nadeem Vawda report at bugs.python.org
Sat Jan 8 00:51:56 CET 2011


Nadeem Vawda <nadeem.vawda at gmail.com> added the comment:

Sorry, scratch that - I misunderstood the semantics of SocketIO.close(). I hadn't realized that the underlying socket is supposed to stay open until it itself is also explicitly closed (as well as all SocketIO objects referring to it).

I've been able to get rid of 2 of the 7 warnings in test_urllib2net with the following change:

  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

It seems that most of the remaining warnings are the result of FTPHandler.ftp_open() not doing anything to close the ftpwrapper objects it creates. I haven't been able to figure out exactly what the correct place to do this is, though.

----------

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


More information about the Python-bugs-list mailing list