summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-11-01 05:10:44 (GMT)
committerBrian Curtin <brian.curtin@gmail.com>2010-11-01 05:10:44 (GMT)
commit50be1ca55ef5d27d6e300b426c870e3a79faf13f (patch)
tree13b6947b1d44786156fcaa07f58f692644dcd13a
parentd4694ed1bbea0adc6f2b5de42e62a424483f2e3d (diff)
downloadcpython-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.
-rw-r--r--Lib/multiprocessing/__init__.py3
-rw-r--r--Lib/test/test_multiprocessing.py6
2 files changed, 7 insertions, 2 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:
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
index 71571d7..f1ccea6 100644
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -1260,7 +1260,11 @@ class _TestManagerRestart(BaseTestCase):
authkey = os.urandom(32)
manager = QueueManager(
address=('localhost', 0), authkey=authkey, serializer=SERIALIZER)
- addr = manager.get_server().address
+ srvr = manager.get_server()
+ addr = srvr.address
+ # Close the connection.Listener socket which gets opened as a part
+ # of manager.get_server(). It's not needed for the test.
+ srvr.listener.close()
manager.start()
p = self.Process(target=self._putter, args=(manager.address, authkey))