changeset: 95468:1a72c0a1a50f parent: 95464:9a0caf6e7a16 parent: 95467:7b168db16e67 user: Victor Stinner date: Tue Apr 07 12:50:24 2015 +0200 files: Lib/urllib/request.py Misc/NEWS description: (Merge 3.4) Issue #23881: urllib.request.ftpwrapper constructor now closes the socket if the FTP connection failed to fix a ResourceWarning. diff -r 9a0caf6e7a16 -r 1a72c0a1a50f Lib/urllib/request.py --- a/Lib/urllib/request.py Tue Apr 07 01:30:33 2015 -0400 +++ b/Lib/urllib/request.py Tue Apr 07 12:50:24 2015 +0200 @@ -2255,7 +2255,11 @@ self.timeout = timeout self.refcount = 0 self.keepalive = persistent - self.init() + try: + self.init() + except: + self.close() + raise def init(self): import ftplib diff -r 9a0caf6e7a16 -r 1a72c0a1a50f Misc/NEWS --- a/Misc/NEWS Tue Apr 07 01:30:33 2015 -0400 +++ b/Misc/NEWS Tue Apr 07 12:50:24 2015 +0200 @@ -19,6 +19,9 @@ Library ------- +- Issue #23881: urllib.request.ftpwrapper constructor now closes the socket if + the FTP connection failed to fix a ResourceWarning. + - Issue #23853: :meth:`socket.socket.sendall` does no more reset the socket timeout each time data is sent successfuly. The socket timeout is now the maximum total duration to send all data.