From: Victor Stinner Date: Tue, 7 Apr 2015 10:49:27 +0000 (+0200) Subject: Issue #23881: urllib.request.ftpwrapper constructor now closes the socket if X-Git-Tag: v3.5.0a4~93^2^2~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ab73e65032565029fdd00e73936dc3b4a197bef6;p=python Issue #23881: urllib.request.ftpwrapper constructor now closes the socket if the FTP connection failed to fix a ResourceWarning. --- diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 6da9007ac8..5cf0cf2e86 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -2240,7 +2240,11 @@ class ftpwrapper: self.timeout = timeout self.refcount = 0 self.keepalive = persistent - self.init() + try: + self.init() + except: + self.close() + raise def init(self): import ftplib diff --git a/Misc/NEWS b/Misc/NEWS index a8c7eccf7e..645e1ade1b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -24,6 +24,9 @@ Core and Builtins Library ------- +- Issue #23881: urllib.request.ftpwrapper constructor now closes the socket if + the FTP connection failed to fix a ResourceWarning. + - Issue #15133: _tkinter.tkapp.getboolean() now supports Tcl_Obj and always returns bool. tkinter.BooleanVar now validates input values (accepted bool, int, str, and Tcl_Obj). tkinter.BooleanVar.get() now always returns bool.