]> granicus.if.org Git - python/commitdiff
Merged revisions 86077 via svnmerge from
authorBrian Curtin <brian.curtin@gmail.com>
Mon, 1 Nov 2010 05:12:34 +0000 (05:12 +0000)
committerBrian Curtin <brian.curtin@gmail.com>
Mon, 1 Nov 2010 05:12:34 +0000 (05:12 +0000)
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
Lib/test/test_multiprocessing.py

index 5a13742b064addbe55601de2e2f7fa8beb2a8516..b808a5b0f3412bc1f8389608b8bf82145b33d05f 100644 (file)
@@ -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:
index 719a2c42a86fbfc317ddedab207d9305e4fed6d4..869cf3bc8aa5299f7d5729edc58e09af88bfc132 100644 (file)
@@ -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))