Cache results of CPU count detection

This commit is contained in:
Kovid Goyal 2014-11-08 18:13:15 +05:30
parent 77ebeb6eea
commit b423ddc87c

View File

@ -469,8 +469,11 @@ class CurrentDir(object):
pass pass
_ncpus = None
def detect_ncpus(): def detect_ncpus():
"""Detects the number of effective CPUs in the system""" """Detects the number of effective CPUs in the system"""
global _ncpus
if _ncpus is None:
if iswindows: if iswindows:
import win32api import win32api
ans = win32api.GetSystemInfo()[5] ans = win32api.GetSystemInfo()[5]
@ -482,7 +485,8 @@ def detect_ncpus():
except Exception: except Exception:
from PyQt5.Qt import QThread from PyQt5.Qt import QThread
ans = QThread.idealThreadCount() ans = QThread.idealThreadCount()
return max(1, ans) _ncpus = max(1, ans)
return _ncpus
relpath = os.path.relpath relpath = os.path.relpath