From: Brian Curtin Date: Fri, 5 Nov 2010 14:48:35 +0000 (+0000) Subject: Shift the pipe-using code into an else block, then close the pipe X-Git-Tag: v3.2a4~139 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=69cd87b5fa284a6ec386d42aa3bcf8e0174ca35b;p=python Shift the pipe-using code into an else block, then close the pipe in finally. Removes two ResourceWarnings. --- diff --git a/Lib/uuid.py b/Lib/uuid.py index df5146428f..5684ad7ace 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -373,10 +373,13 @@ def _ipconfig_getnode(): pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all') except IOError: continue - for line in pipe: - value = line.split(':')[-1].strip().lower() - if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value): - return int(value.replace('-', ''), 16) + else: + for line in pipe: + value = line.split(':')[-1].strip().lower() + if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value): + return int(value.replace('-', ''), 16) + finally: + pipe.close() def _netbios_getnode(): """Get the hardware address on Windows using NetBIOS calls.