Kaydet (Commit) 50be1ca5 authored tarafından Brian Curtin's avatar Brian Curtin

Fix some ResourceErrors.

Use a context manager for os.popen and explicitly close a socket.
üst d4694ed1
...@@ -115,7 +115,8 @@ def cpu_count(): ...@@ -115,7 +115,8 @@ def cpu_count():
num = 0 num = 0
elif 'bsd' in sys.platform or sys.platform == 'darwin': elif 'bsd' in sys.platform or sys.platform == 'darwin':
try: 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: except ValueError:
num = 0 num = 0
else: else:
......
...@@ -1260,7 +1260,11 @@ class _TestManagerRestart(BaseTestCase): ...@@ -1260,7 +1260,11 @@ class _TestManagerRestart(BaseTestCase):
authkey = os.urandom(32) authkey = os.urandom(32)
manager = QueueManager( manager = QueueManager(
address=('localhost', 0), authkey=authkey, serializer=SERIALIZER) 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() manager.start()
p = self.Process(target=self._putter, args=(manager.address, authkey)) p = self.Process(target=self._putter, args=(manager.address, authkey))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment