diff options
author | Brian Curtin <brian.curtin@gmail.com> | 2010-11-01 05:10:44 (GMT) |
---|---|---|
committer | Brian Curtin <brian.curtin@gmail.com> | 2010-11-01 05:10:44 (GMT) |
commit | 50be1ca55ef5d27d6e300b426c870e3a79faf13f (patch) | |
tree | 13b6947b1d44786156fcaa07f58f692644dcd13a /Lib/multiprocessing | |
parent | d4694ed1bbea0adc6f2b5de42e62a424483f2e3d (diff) | |
download | cpython-50be1ca55ef5d27d6e300b426c870e3a79faf13f.zip cpython-50be1ca55ef5d27d6e300b426c870e3a79faf13f.tar.gz cpython-50be1ca55ef5d27d6e300b426c870e3a79faf13f.tar.bz2 |
Fix some ResourceErrors.
Use a context manager for os.popen and explicitly close a socket.
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r-- | Lib/multiprocessing/__init__.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/multiprocessing/__init__.py b/Lib/multiprocessing/__init__.py index e4af68b..c0e00cd 100644 --- a/Lib/multiprocessing/__init__.py +++ b/Lib/multiprocessing/__init__.py @@ -115,7 +115,8 @@ def cpu_count(): num = 0 elif 'bsd' in sys.platform or sys.platform == 'darwin': try: - num = int(os.popen('sysctl -n hw.ncpu').read()) + with os.popen('sysctl -n hw.ncpu') as p: + num = int(p.read()) except ValueError: num = 0 else: |