Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e2fadc

Browse files
committed
Merged revisions 86077 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 4531f8d commit 9e2fadc

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/multiprocessing/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ def cpu_count():
115115
num = 0
116116
elif 'bsd' in sys.platform or sys.platform == 'darwin':
117117
try:
118-
num = int(os.popen('sysctl -n hw.ncpu').read())
118+
with os.popen('sysctl -n hw.ncpu') as p:
119+
num = int(p.read())
119120
except ValueError:
120121
num = 0
121122
else:

Lib/test/test_multiprocessing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,11 @@ def test_rapid_restart(self):
12251225
authkey = os.urandom(32)
12261226
manager = QueueManager(
12271227
address=('localhost', 0), authkey=authkey, serializer=SERIALIZER)
1228-
addr = manager.get_server().address
1228+
srvr = manager.get_server()
1229+
addr = srvr.address
1230+
# Close the connection.Listener socket which gets opened as a part
1231+
# of manager.get_server(). It's not needed for the test.
1232+
srvr.listener.close()
12291233
manager.start()
12301234

12311235
p = self.Process(target=self._putter, args=(manager.address, authkey))

0 commit comments

Comments
 (0)