mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Fix some ResourceErrors.
Use a context manager for os.popen and explicitly close a socket.
This commit is contained in:
parent
d4694ed1bb
commit
50be1ca55e
2 changed files with 7 additions and 2 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue