示例#1
0
def detect_ncpus():
    """Detects the number of effective CPUs in the system"""
    if iswindows:
        import win32api
        ans = win32api.GetSystemInfo()[5]
    else:
        import multiprocessing
        ans = -1
        try:
            ans = multiprocessing.cpu_count()
        except Exception:
            from PyQt5.Qt import QThread
            ans = QThread.idealThreadCount()
    return max(1, ans)
def detect_ncpus():
    """Detects the number of effective CPUs in the system"""
    global _ncpus
    if _ncpus is None:
        if iswindows:
            import win32api
            ans = win32api.GetSystemInfo()[5]
        else:
            import multiprocessing
            ans = -1
            try:
                ans = multiprocessing.cpu_count()
            except Exception:
                ans = 1
        _ncpus = max(1, ans)
    return _ncpus