| 1 |
''' |
| 2 |
Module of MacOS API for plyer.cpu. |
| 3 |
''' |
| 4 |
|
| 5 |
from subprocess import Popen, PIPE |
| 6 |
from plyer.facades import CPU |
| 7 |
from plyer.utils import whereis_exe |
| 8 |
|
| 9 |
|
| 10 |
class OSXCPU(CPU): |
| 11 |
''' |
| 12 |
Implementation of MacOS CPU API. |
| 13 |
''' |
| 14 |
|
| 15 |
@staticmethod |
| 16 |
def _sockets(): |
| 17 |
return |
| 18 |
|
| 19 |
def _physical(self): |
| 20 |
|
| 21 |
physical = None |
| 22 |
|
| 23 |
_physical = Popen( |
| 24 |
['sysctl', '-n', 'hw.physicalcpu_max'], |
| 25 |
stdout=PIPE |
| 26 |
) |
| 27 |
output = _physical.communicate()[0].decode('utf-8').strip() |
| 28 |
if output: |
| 29 |
physical = int(output) |
| 30 |
return physical |
| 31 |
|
| 32 |
def _logical(self): |
| 33 |
|
| 34 |
logical = None |
| 35 |
|
| 36 |
_logical = Popen( |
| 37 |
['sysctl', '-n', 'hw.logicalcpu_max'], |
| 38 |
stdout=PIPE |
| 39 |
) |
| 40 |
output = _logical.communicate()[0].decode('utf-8').strip() |
| 41 |
if output: |
| 42 |
logical = int(output) |
| 43 |
return logical |
| 44 |
|
| 45 |
@staticmethod |
| 46 |
def _cache(): |
| 47 |
return |
| 48 |
|
| 49 |
@staticmethod |
| 50 |
def _numa(): |
| 51 |
return |
| 52 |
|
| 53 |
|
| 54 |
def instance(): |
| 55 |
''' |
| 56 |
Instance for facade proxy. |
| 57 |
''' |
| 58 |
import sys |
| 59 |
if whereis_exe('sysctl'): |
| 60 |
return OSXCPU() |
| 61 |
sys.stderr.write('sysctl not found.') |
| 62 |
return CPU() |