Esempio n. 1
0
    def SetProcessorAffinity(self, mask=1):
        """
        Set the processor affinity for the current process (i.e., select
        which processor(s) the process should run on).  This will affect
        this process and any child processes.
        
        @param val: The 
        
        """
        try:
            import win32process

            # get number of processors
            systemInfo = win32api.GetSystemInfo()
            numprocs = systemInfo[5]

            # if multiple procs, set processor affinity to the first
            # this sets proc affinity for children also, so vic will get this
            # (vic is ill-behaved on multiproc machines)
            if numprocs > 1:
                log.info("Found %d processors; setting affinity", numprocs)
                cp = win32api.GetCurrentProcess()
                win32process.SetProcessAffinityMask(cp, mask)

        except Exception, e:
            log.exception("Exception setting processor affinity; mask=%d",
                          mask)
Esempio n. 2
0
def get_machine_and_user():
    #
    # first determine machine type
    #
    ret_dict = {}
    import os, string
    if os.name == 'nt':
        ret_dict['MACHINETYPE'] = 'PC'
        import win32api
        try:
            ret_dict['USERNAME'] = string.replace(win32api.GetUserName(), ' ',
                                                  '_')
        except:
            ret_dict['USERNAME'] = ''
        proctype = win32api.GetSystemInfo()[6]
        if ` proctype ` [-2:] == '86':
            ret_dict['PROCESSORTYPE'] = 'intel'
        else:
            ret_dict['PROCESSORTYPE'] = 'alpha'
        gvex = win32api.GetVersionEx()
        if gvex[3] == 1:
            ret_dict['OPSYSTEM'] = '9X'
            ret_dict['USERDIRECTORY'] = ''
        else:
            ret_dict['OPSYSTEM'] = 'NT'
            ret_dict['USERDIRECTORY'] = os.environ['USERPROFILE']
        ret_dict['OPVERSION'] = ` gvex[0] ` + '.' + ` gvex[1] `
Esempio n. 3
0
   def getProcessorCount():
       """Return the number of processors/cores in the current system.
 
 Useful for determining the maximum parallelism of the current system.
 
 @return: The number of processors/cores in the current system.
 @rtype: int
 """
       return win32api.GetSystemInfo()[5]
Esempio n. 4
0
 def __init__(self, update_interval=2):
     self.format = win32pdh.PDH_FMT_DOUBLE
     self.hcs = []
     self.hqs = []
     self._setup_query("_Total")
     num_cpus = win32api.GetSystemInfo()[4]
     for x in xrange(num_cpus):
         self._setup_query(x)
     CPUMeterBase.__init__(self, update_interval)
Esempio n. 5
0
 def cpu_count():
     #The multiprocessing cpu_count implementation is flaky on windows - so we do it the official windows way
     # (it looks for an environment variable that may not be there)
     (wProcessorArchitecture,
         dwPageSize,
         lpMinimumApplicationAddress,
         lpMaximumApplicationAddress,
         dwActiveProcessorMask,
         dwNumberOfProcessors,
         dwProcessorType,
         dwAllocationGranularity,
         (wProcessorLevel,wProcessorRevision)) = win32api.GetSystemInfo()
     return dwNumberOfProcessors
Esempio n. 6
0
 def __init__(self):
     _version = platform.version().split('.')
     if len(_version) == 2:
         self.major = int(_version[0])
         self.minor = int(_version[1])
         self.build = 0
     else:
         self.major = int(_version[0])
         self.minor = int(_version[1])
         self.build = int(_version[2])
     self.wProductType = win32api.GetVersionEx(1)[8]
     self.wProcessorArchitecture = win32api.GetSystemInfo()[0]
     self.bits = 64 if platform.machine().endswith('64') else 32
     _v = self.version
     self.version_full = _v.full
     self.version_short = _v.short
     self.server = _v.server
Esempio n. 7
0
    def get_cores(self):
        """ Returns the number of cores available in the system """
        if (sys.platform == "win32") or (sys.platform == "win64"):
            logical_cores = win32api.GetSystemInfo()[5]  #Logical Cores
            return logical_cores

        try:
            proc = open("/proc/cpuinfo", "r")
        except:
            return 1  # if we can't open /PROC/CPUINFO, return only one CPU (just in case)

        siblings = 1  # default values
        cpu_cores = 1  # for siblings and cpu cores
        notfirst = False
        ncores = 0
        while (True):
            line = proc.readline()

            if (((line[:9] == "processor") and notfirst) or (line == "")):

                # each entry is equivalent to CPU_CORES/SIBLINGS real cores
                # (always 1 except in HyperThreading systems, where it counts 1/2)

                ncores += (float(cpu_cores)) / (float(siblings))
                siblings = 1
                cpu_cores = 1

            if line == "":
                break

            if line[:9] == "processor":
                notfirst = True
            elif (line[:8] == "siblings"):
                siblings = self.get_number(line)
            elif (line[:9] == "cpu cores"):
                cpu_cores = self.get_number(line)

        if (ncores <= 1.0):
            return 1
        else:
            return int(ncores)
Esempio n. 8
0
def getCPUsAlt():
    a, b, c, d, e, f, g, h, u = win32api.GetSystemInfo()
    return int(f)
Esempio n. 9
0
 def test_cpu_count_2(self):
     sys_value = win32api.GetSystemInfo()[5]
     psutil_value = psutil.cpu_count()
     self.assertEqual(sys_value, psutil_value)
Esempio n. 10
0
import logging
import logging.handlers
import os
import atexit
from ZODB.FileStorage import FileStorage
from ZODB.DB import DB as ZDB

from Crypto.Hash import SHA
import win32api
import marshal
from Crypto.Cipher import Blowfish
import types
hash = SHA.new()
d, p = os.path.splitdrive(win32api.GetSystemDirectory())
hash.update(str(win32api.GetSystemInfo()))
hash.update(APPNAME)
hash.update(str(win32api.GetVolumeInformation(d + '/')))
HWINFO = hash.hexdigest()
cipher = Blowfish.new(HWINFO)

egg = os.path.expanduser('~/' + APPNAME)
HOMEDIR = unicode(egg, encoding=sys.getfilesystemencoding())
if not os.path.isdir(HOMEDIR):
    os.mkdir(HOMEDIR)

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(
    "%(asctime)s - %(levelname)s - %(module)s: %(message)s")
logname = os.path.expanduser(os.path.join(HOMEDIR, APPNAME + '.log'))
Esempio n. 11
0
import win32api, mmapfile
import winerror
import tempfile, os
from pywin32_testutil import str2bytes

system_info = win32api.GetSystemInfo()
page_size = system_info[1]
alloc_size = system_info[7]

fname = tempfile.mktemp()
mapping_name = os.path.split(fname)[1]
fsize = 8 * page_size
print(fname, fsize, mapping_name)

m1 = mmapfile.mmapfile(File=fname, Name=mapping_name, MaximumSize=fsize)
m1.seek(100)
m1.write_byte(str2bytes("?"))
m1.seek(-1, 1)
assert m1.read_byte() == str2bytes("?")

## A reopened named mapping should have exact same size as original mapping
m2 = mmapfile.mmapfile(Name=mapping_name, File=None, MaximumSize=fsize * 2)
assert m2.size() == m1.size()
m1.seek(0, 0)
m1.write(fsize * str2bytes("s"))
assert m2.read(fsize) == fsize * str2bytes("s")

move_src = 100
move_dest = 500
move_size = 150
Esempio n. 12
0
    def __init__( self ):
        AGService.__init__( self )
        self.thepath = os.getcwd()

        self.capabilities = [ Capability( Capability.CONSUMER,
                                          Capability.VIDEO,
                                          "H261",
                                          90000, self.id),
                              Capability( Capability.PRODUCER,
                                          Capability.VIDEO,
                                          "H261",
                                          90000, self.id)]
        if IsWindows():
            vic = "vic.exe"
        else:
            vic = "vic"

        self.executable = os.path.join(os.getcwd(),vic)
        if not os.path.isfile(self.executable):
            self.executable = vic

        self.sysConf = SystemConfig.instance()

        self.profile = None
        self.windowGeometry = None
        
        self.startPriority = '7'
        self.startPriorityOption.value = self.startPriority
        self.id = str(GUID())

        # Set configuration parameters
        # note: the datatype of the port parameter changes when a resource is set!
        self.streamname = TextParameter( "Stream Name", "" )
        self.port = TextParameter( "port", "" )
        self.encoding = OptionSetParameter( "Encoding", "h261", VideoService.encodingOptions )
        if IsWindows(): 
            standard = "PAL"
        else:
            standard = "NTSC"
        self.standard = OptionSetParameter( "Standard", standard, VideoService.standardOptions )
        self.tiles = OptionSetParameter( "Thumbnail Columns", "4", VideoService.tileOptions )
        self.bandwidth = RangeParameter( "Bandwidth", 800, 0, 3072 )
        self.framerate = RangeParameter( "Frame Rate", 24, 1, 30 )
        self.quality = RangeParameter( "Quality", 75, 1, 100 )
        self.transmitOnStart = OptionSetParameter( "Transmit on Startup", "On", VideoService.onOffOptions )
        self.muteSources = OptionSetParameter( "Mute Sources", "Off", VideoService.onOffOptions )
        self.positionWindow = OptionSetParameter( 'Position Window', 'Justify Left', ['Off', 'Justify Left', 'Justify Right'])
        
        self.configuration.append( self.streamname )
        self.configuration.append( self.port )
        self.configuration.append( self.encoding )
        self.configuration.append( self.standard )
        self.configuration.append( self.tiles )
        self.configuration.append( self.bandwidth )
        self.configuration.append( self.framerate )
        self.configuration.append (self.quality )
        self.configuration.append (self.transmitOnStart )
        self.configuration.append (self.muteSources )
        self.configuration.append (self.positionWindow )
        if IsWindows():
            try:
                import win32api

                # get number of processors
                systemInfo = win32api.GetSystemInfo()
                numprocs = systemInfo[5]
                self.allProcsMask = 2**numprocs-1

                self.procOptions = ['All']
                for i in range(numprocs):
                    self.procOptions.append(str(i+1))

                self.processorUsage = OptionSetParameter( "Processor usage", self.procOptions[0], self.procOptions )
                self.configuration.append( self.processorUsage )
            except:
                self.log.exception('Error initializing processor usage options')

        self.__GetResources()
Esempio n. 13
0
print(api.GetCommandLine())
print(api.GetCursorPos())
print(api.GetDomainName())
print(api.GetEnvironmentVariable('path'))
print(api.GetFileAttributes('.'))
print(api.GetFileVersionInfo('C:\\windows\\system32\\cmd.exe', "\\"))
print(api.GetFullPathName('.'))
print(api.GetLocalTime())
print(api.GetLogicalDriveStrings().replace('\x00', ' '))
print(api.GetLogicalDrives())
print(api.GetLongPathName('C:'))
print(api.GetModuleFileName(0))
print(api.GetNativeSystemInfo())
print(hex(api.GetSysColor(con.COLOR_WINDOW)))
print(api.GetSystemDirectory())
print(api.GetSystemInfo())
print(api.GetSystemMetrics(con.SM_CXSCREEN))
print(api.GetSystemTime())
print(api.GetTickCount())
# print(api.GetTimeZoneInformation())
print(api.GetUserDefaultLangID())
print(api.GetUserName())
print(api.GetVersion())
print(api.GetVolumeInformation('C:'))
print(api.GetWindowsDirectory())
print(api.GlobalMemoryStatus())
print(api.MessageBeep())
print(api.MessageBox(0, 'hello', 'world', con.MB_OK))
size = api.RegQueryInfoKey(con.HKEY_LOCAL_MACHINE)
print(size)
for i in range(size[0]):
    def __init__(self):
        AGService.__init__(self)
        self.thepath = os.getcwd()

        if IsWindows():
            vic = "vic.exe"
        else:
            vic = "vic"

        self.executable = os.path.join(os.getcwd(), vic)
        if not os.path.isfile(self.executable):
            self.executable = vic

        proc = subprocess.Popen([self.executable, '-Q'],
                                stdin=subprocess.PIPE,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        self.deviceDOM = xml.dom.minidom.parse(proc.stdout)

        self.encodingOptions = []
        self.capabilities = []
        codecs = self.deviceDOM.getElementsByTagName("codec")
        for codec in codecs:
            if codec.childNodes[0].nodeType == xml.dom.minidom.Node.TEXT_NODE:
                if codec.childNodes[0].data in ['h263', 'h263+', 'raw', 'pvh']:
                    continue
                self.encodingOptions.append(codec.childNodes[0].data)
                self.capabilities.append(
                    Capability(Capability.CONSUMER, Capability.VIDEO,
                               codec.childNodes[0].data.upper(), 90000,
                               self.id))

                self.capabilities.append(
                    Capability(Capability.PRODUCER, Capability.VIDEO,
                               codec.childNodes[0].data.upper(), 90000,
                               self.id))

        self.sysConf = SystemConfig.instance()

        self.profile = None
        self.windowGeometry = None

        self.startPriority = '7'
        self.startPriorityOption.value = self.startPriority
        self.id = str(GUID())

        self.resolution = None

        # Set configuration parameters
        # note: the datatype of the port, standard and inputsize parameters change when a resource is set!
        self.streamname = TextParameter("Stream Name", "")
        self.port = TextParameter("port", "")
        self.encoding = OptionSetParameter("Encoding", "mpeg4",
                                           self.encodingOptions)
        self.standard = TextParameter("standard", "")
        self.tiles = OptionSetParameter("Thumbnail Columns", "4",
                                        VideoServiceH264.tileOptions)
        self.bandwidth = RangeParameter("Bandwidth", 2500, 0, 10240)
        self.framerate = RangeParameter("Frame Rate", 24, 1, 30)
        self.quality = RangeParameter("Quality", 75, 1, 100)
        self.transmitOnStart = OptionSetParameter(
            "Transmit on Startup", "On", VideoServiceH264.onOffOptions)
        self.muteSources = OptionSetParameter("Mute Sources", "Off",
                                              VideoServiceH264.onOffOptions)
        self.inputsize = TextParameter("inputsize", "")
        self.positionWindow = OptionSetParameter(
            'Position Window', 'Justify Left',
            ['Off', 'Justify Left', 'Justify Right'])
        self.encodingDeinterlacer = OptionSetParameter(
            "Encoding Deinterlacer", "Off", VideoServiceH264.onOffOptions)

        self.configuration.append(self.streamname)
        self.configuration.append(self.port)
        self.configuration.append(self.encoding)
        self.configuration.append(self.standard)
        self.configuration.append(self.tiles)
        self.configuration.append(self.bandwidth)
        self.configuration.append(self.framerate)
        self.configuration.append(self.quality)
        self.configuration.append(self.transmitOnStart)
        self.configuration.append(self.muteSources)
        self.configuration.append(self.inputsize)

        self.configuration.append(self.positionWindow)
        self.configuration.append(self.encodingDeinterlacer)
        if IsWindows():
            try:
                import win32api

                # get number of processors
                systemInfo = win32api.GetSystemInfo()
                numprocs = systemInfo[5]
                self.allProcsMask = 2**numprocs - 1

                self.procOptions = ['All']
                for i in range(numprocs):
                    self.procOptions.append(str(i + 1))

                self.processorUsage = OptionSetParameter(
                    "Processor usage", self.procOptions[0], self.procOptions)
                self.configuration.append(self.processorUsage)
            except:
                self.log.exception(
                    'Error initializing processor usage options')

        self.__GetResources()
        self.deviceDOM.unlink()
Esempio n. 15
0
    def __init__( self ):
        AGService.__init__( self )

        if IsWindows():
            vic = "vic.exe"
        else:
            vic = "vic"

        self.executable = os.path.join(os.getcwd(),vic)
        if not os.path.isfile(self.executable):
            self.executable = vic

        proc = subprocess.Popen([self.executable, '-Q'],
                                stdin=subprocess.PIPE,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        deviceDOM = xml.dom.minidom.parse(proc.stdout)

        self.capabilities = []
        codecs = deviceDOM.getElementsByTagName("codec")
        for codec in codecs:
            if codec.childNodes[0].nodeType == xml.dom.minidom.Node.TEXT_NODE:
                if codec.childNodes[0].data in ['h263', 'h263+', 'raw', 'pvh']:
                    continue
                self.capabilities.append(Capability( Capability.CONSUMER,
                                          Capability.VIDEO,
                                          codec.childNodes[0].data.upper(),
                                          90000, self.id))
        deviceDOM.unlink()

        self.sysConf = SystemConfig.instance()

        self.profile = None
        self.windowGeometry = None

        self.startPriority = '7'
        self.startPriorityOption.value = self.startPriority

        # Set configuration parameters
        self.tiles = OptionSetParameter( "Thumbnail Columns", "4", VideoConsumerServiceH264.tileOptions )
        self.positionWindow = OptionSetParameter( 'Position Window', 'Justify Left', ['Off', 'Justify Left', 'Justify Right'])
        
        self.configuration.append( self.tiles )
        self.configuration.append( self.positionWindow)

        if IsWindows():
            try:
                import win32api

                # get number of processors
                systemInfo = win32api.GetSystemInfo()
                numprocs = systemInfo[5]
                self.allProcsMask = 2**numprocs-1

                self.procOptions = ['All']
                for i in range(numprocs):
                    self.procOptions.append(str(i+1))

                self.processorUsage = OptionSetParameter( "Processor usage", self.procOptions[0], self.procOptions )
                self.configuration.append( self.processorUsage )
            except:
                self.log.exception('Error initializing processor usage options')
  File "/usr/pkg/lib/python2.7/multiprocessing/pool.py", line 223, in _repopulate_pool
    w.start()
  File "/usr/pkg/lib/python2.7/multiprocessing/dummy/__init__.py", line 75, in start
    threading.Thread.start(self)
  File "/usr/pkg/lib/python2.7/threading.py", line 745, in start
    _start_new_thread(self.__bootstrap, ())
thread.error: can't start new thread
 *** Error code 1

(The same chunk works fine in the interactive shell, not sure why
it so reliably breaks. -- wiz 20150207)

See also
http://debian.2.n7.nabble.com/Bug-760865-calibre-FTBFS-on-mips-thread-error-can-t-start-new-thread-td3353306.html

--- setup/build_environment.py.orig	2015-02-07 14:26:27.000000000 +0000
+++ setup/build_environment.py
@@ -43,11 +43,7 @@ if iswindows:
     import win32api
     cpu_count = win32api.GetSystemInfo()[5]
 else:
-    from multiprocessing import cpu_count
-    try:
-        cpu_count = cpu_count()
-    except NotImplementedError:
-        cpu_count = 1
+    cpu_count = 1
 
 def run_pkgconfig(name, envvar, default, flag, prefix):
     ans = []
Esempio n. 17
0
def getInfo():
    return Info(*win32api.GetSystemInfo())
Esempio n. 18
0
 def test_cpu_count_vs_GetSystemInfo(self):
     # Will likely fail on many-cores systems:
     # https://stackoverflow.com/questions/31209256
     sys_value = win32api.GetSystemInfo()[5]
     psutil_value = psutil.cpu_count()
     self.assertEqual(sys_value, psutil_value)
Esempio n. 19
0
    def __init__(self):
        AGService.__init__(self)
        self.capabilities = [
            Capability(Capability.PRODUCER, Capability.VIDEO, "H261", 90000,
                       self.id)
        ]

        if IsWindows():
            vic = "vic.exe"
        else:
            vic = "vic"

        self.executable = os.path.join(os.getcwd(), vic)
        if not os.path.isfile(self.executable):
            self.executable = vic

        self.sysConf = SystemConfig.instance()

        self.startPriority = '5'
        self.startPriorityOption.value = self.startPriority
        self.id = str(GUID())

        # Set configuration parameters

        # note: the datatype of the port parameter changes when a resource is set!
        self.streamname = TextParameter("Stream Name", "")
        self.port = TextParameter("Port", "")
        self.encoding = OptionSetParameter("Encoding", "h261",
                                           VideoProducerService.encodings)
        if IsWindows():
            standard = "PAL"
        else:
            standard = "NTSC"
        self.standard = OptionSetParameter("Standard", standard,
                                           VideoProducerService.standards)
        self.bandwidth = RangeParameter("Bandwidth", 800, 0, 3072)
        self.framerate = RangeParameter("Frame Rate", 24, 1, 30)
        self.quality = RangeParameter("Quality", 75, 1, 100)
        self.configuration.append(self.streamname)
        self.configuration.append(self.port)
        self.configuration.append(self.encoding)
        self.configuration.append(self.standard)
        self.configuration.append(self.bandwidth)
        self.configuration.append(self.framerate)
        self.configuration.append(self.quality)

        if IsWindows():
            try:
                import win32api

                # get number of processors
                systemInfo = win32api.GetSystemInfo()
                numprocs = systemInfo[5]
                self.allProcsMask = 2**numprocs - 1

                self.procOptions = ['All']
                for i in range(numprocs):
                    self.procOptions.append(str(i + 1))

                self.processorUsage = OptionSetParameter(
                    "Processor usage", self.procOptions[0], self.procOptions)
                self.configuration.append(self.processorUsage)
            except:
                self.log.exception(
                    'Error initializing processor usage options')

        self.profile = None
        self.resource = ''

        self.__GetResources()