[Python-checkins] r86009 - python/branches/py3k/Lib/uuid.py
brian.curtin
python-checkins at python.org
Sun Oct 31 02:10:58 CET 2010
Author: brian.curtin
Date: Sun Oct 31 02:10:58 2010
New Revision: 86009
Log:
Fix ResourceWarning for unclosed files (from os.popen)
Modified:
python/branches/py3k/Lib/uuid.py
Modified: python/branches/py3k/Lib/uuid.py
==============================================================================
--- python/branches/py3k/Lib/uuid.py (original)
+++ python/branches/py3k/Lib/uuid.py Sun Oct 31 02:10:58 2010
@@ -322,15 +322,15 @@
# LC_ALL to get English output, 2>/dev/null to
# prevent output on stderr
cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
- pipe = os.popen(cmd)
+ with os.popen(cmd) as pipe:
+ for line in pipe:
+ words = line.lower().split()
+ for i in range(len(words)):
+ if words[i] in hw_identifiers:
+ return int(
+ words[get_index(i)].replace(':', ''), 16)
except IOError:
continue
-
- for line in pipe:
- words = line.lower().split()
- for i in range(len(words)):
- if words[i] in hw_identifiers:
- return int(words[get_index(i)].replace(':', ''), 16)
return None
def _ifconfig_getnode():
More information about the Python-checkins
mailing list