]> granicus.if.org Git - python/commitdiff
Shift the pipe-using code into an else block, then close the pipe
authorBrian Curtin <brian.curtin@gmail.com>
Fri, 5 Nov 2010 14:48:35 +0000 (14:48 +0000)
committerBrian Curtin <brian.curtin@gmail.com>
Fri, 5 Nov 2010 14:48:35 +0000 (14:48 +0000)
in finally. Removes two ResourceWarnings.

Lib/uuid.py

index df5146428f092d352c466bb32bf492292e19d40b..5684ad7aceece0a916103ad460478d9973d5167a 100644 (file)
@@ -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.