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

Skip to content

Commit 50be1ca

Browse files
committed
Fix some ResourceErrors.
Use a context manager for os.popen and explicitly close a socket.
1 parent d4694ed commit 50be1ca

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
@@ -1260,7 +1260,11 @@ def test_rapid_restart(self):
12601260
authkey = os.urandom(32)
12611261
manager = QueueManager(
12621262
address=('localhost', 0), authkey=authkey, serializer=SERIALIZER)
1263-
addr = manager.get_server().address
1263+
srvr = manager.get_server()
1264+
addr = srvr.address
1265+
# Close the connection.Listener socket which gets opened as a part
1266+
# of manager.get_server(). It's not needed for the test.
1267+
srvr.listener.close()
12641268
manager.start()
12651269

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

0 commit comments

Comments
 (0)