]> granicus.if.org Git - python/commitdiff
Fix some ResourceErrors.
authorBrian Curtin <brian.curtin@gmail.com>
Mon, 1 Nov 2010 05:10:44 +0000 (05:10 +0000)
committerBrian Curtin <brian.curtin@gmail.com>
Mon, 1 Nov 2010 05:10:44 +0000 (05:10 +0000)
Use a context manager for os.popen and explicitly close a socket.

Lib/multiprocessing/__init__.py
Lib/test/test_multiprocessing.py

index e4af68bed1a6849a6c696dd9c33c692d96ff78db..c0e00cd93da51dca1251d2d7ff27c77691219b2b 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 71571d760ff5737322c62f0bff122f2f91d1a488..f1ccea658e6a8e09fb0608aee9ca3a159c2760c8 100644 (file)
@@ -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))