From 9e2fadcbddbb0de515fc8c920c5de9181d6f604b Mon Sep 17 00:00:00 2001 From: Brian Curtin Date: Mon, 1 Nov 2010 05:12:34 +0000 Subject: [PATCH] Merged revisions 86077 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r86077 | brian.curtin | 2010-11-01 00:10:44 -0500 (Mon, 01 Nov 2010) | 3 lines Fix some ResourceErrors. Use a context manager for os.popen and explicitly close a socket. ........ --- Lib/multiprocessing/__init__.py | 3 ++- Lib/test/test_multiprocessing.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/multiprocessing/__init__.py b/Lib/multiprocessing/__init__.py index 5a13742b06..b808a5b0f3 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 719a2c42a8..869cf3bc8a 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -1225,7 +1225,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)) -- 2.40.0