[Python-checkins] r86077 - in python/branches/py3k/Lib: multiprocessing/__init__.py test/test_multiprocessing.py

brian.curtin python-checkins at python.org
Mon Nov 1 06:10:44 CET 2010


Author: brian.curtin
Date: Mon Nov  1 06:10:44 2010
New Revision: 86077

Log:
Fix some ResourceErrors.
Use a context manager for os.popen and explicitly close a socket.


Modified:
   python/branches/py3k/Lib/multiprocessing/__init__.py
   python/branches/py3k/Lib/test/test_multiprocessing.py

Modified: python/branches/py3k/Lib/multiprocessing/__init__.py
==============================================================================
--- python/branches/py3k/Lib/multiprocessing/__init__.py	(original)
+++ python/branches/py3k/Lib/multiprocessing/__init__.py	Mon Nov  1 06:10:44 2010
@@ -115,7 +115,8 @@
             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:

Modified: python/branches/py3k/Lib/test/test_multiprocessing.py
==============================================================================
--- python/branches/py3k/Lib/test/test_multiprocessing.py	(original)
+++ python/branches/py3k/Lib/test/test_multiprocessing.py	Mon Nov  1 06:10:44 2010
@@ -1260,7 +1260,11 @@
         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))


More information about the Python-checkins mailing list