Skip to content

Commit

Permalink
Close popen file handle when reading cpu count on Mac OS.
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Jan 6, 2022
1 parent 0809aca commit ce5961b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions qutip/hardware_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@


def _mac_hardware_info():
info = dict()
results = dict()
for l in [l.split(':') for l in os.popen('sysctl hw').readlines()[1:]]:
info[l[0].strip(' "').replace(' ', '_').lower().strip('hw.')] = \
l[1].strip('.\n ')
info = {}
results = {}
with os.popen('sysctl hw') as f:
lines = f.readlines()
for line in lines[1:]:
key, _, value = line.partition(':')
key = key.strip(' "').replace(' ', '_').lower().strip('hw.')
value = value.strip('.\n ')
info[key] = value
results.update({'cpus': int(info['physicalcpu'])})
# Mac OS currently doesn't not provide hw.cpufrequency on the M1
with os.popen('sysctl hw.cpufrequency') as f:
Expand Down

0 comments on commit ce5961b

Please sign in to comment.