Issue #22131: Fixed a bug in handling an error occured during reading from
a pipe in _ipconfig_getnode().
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 63cb3ae..7b9b373 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -366,13 +366,11 @@
pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all')
except IOError:
continue
- else:
+ with pipe:
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.