File: cpu.py

package info (click to toggle)
python-plyer 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,808 kB
  • sloc: python: 13,395; sh: 217; makefile: 177
file content (62 lines) | stat: -rw-r--r-- 1,224 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'''
Module of MacOS API for plyer.cpu.
'''

from subprocess import Popen, PIPE
from plyer.facades import CPU
from plyer.utils import whereis_exe


class OSXCPU(CPU):
    '''
    Implementation of MacOS CPU API.
    '''

    @staticmethod
    def _sockets():
        return

    def _physical(self):
        # cores
        physical = None

        _physical = Popen(
            ['sysctl', '-n', 'hw.physicalcpu_max'],
            stdout=PIPE
        )
        output = _physical.communicate()[0].decode('utf-8').strip()
        if output:
            physical = int(output)
        return physical

    def _logical(self):
        # cores * threads
        logical = None

        _logical = Popen(
            ['sysctl', '-n', 'hw.logicalcpu_max'],
            stdout=PIPE
        )
        output = _logical.communicate()[0].decode('utf-8').strip()
        if output:
            logical = int(output)
        return logical

    @staticmethod
    def _cache():
        return

    @staticmethod
    def _numa():
        return


def instance():
    '''
    Instance for facade proxy.
    '''
    import sys
    if whereis_exe('sysctl'):
        return OSXCPU()
    sys.stderr.write('sysctl not found.')
    return CPU()