From 6a5acd3fe7e39552b96889fca4a4c8b95cf4b206 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 12 Jul 2014 18:08:55 +0530 Subject: [PATCH] Avoid using PyQt to detect the number of CPUs on windows --- src/calibre/__init__.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index 6d136c5012..9d599c9cf0 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -471,16 +471,18 @@ class CurrentDir(object): def detect_ncpus(): """Detects the number of effective CPUs in the system""" - import multiprocessing - ans = -1 - try: - ans = multiprocessing.cpu_count() - except: - from PyQt5.Qt import QThread - ans = QThread.idealThreadCount() - if ans < 1: - ans = 1 - return ans + 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) relpath = os.path.relpath