mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-13 18:17:08 -07:00
[search engine] Fix cpu_count in old Python versions
This commit is contained in:
parent
6668018b45
commit
32c813eece
2 changed files with 16 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
#VERSION: 1.40
|
#VERSION: 1.41
|
||||||
|
|
||||||
# Author:
|
# Author:
|
||||||
# Fabien Devaux <fab AT gnux DOT info>
|
# Fabien Devaux <fab AT gnux DOT info>
|
||||||
|
@ -41,6 +41,11 @@ from multiprocessing import Pool, cpu_count
|
||||||
from fix_encoding import fix_encoding
|
from fix_encoding import fix_encoding
|
||||||
|
|
||||||
THREADED = True
|
THREADED = True
|
||||||
|
try:
|
||||||
|
MAX_THREADS = cpu_count()
|
||||||
|
except NotImplementedError:
|
||||||
|
MAX_THREADS = 1
|
||||||
|
|
||||||
CATEGORIES = {'all', 'movies', 'tv', 'music', 'games', 'anime', 'software', 'pictures', 'books'}
|
CATEGORIES = {'all', 'movies', 'tv', 'music', 'games', 'anime', 'software', 'pictures', 'books'}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -170,7 +175,7 @@ def main(args):
|
||||||
|
|
||||||
if THREADED:
|
if THREADED:
|
||||||
#child process spawning is controlled min(number of searches, number of cpu)
|
#child process spawning is controlled min(number of searches, number of cpu)
|
||||||
pool = Pool(min(len(engines_list), cpu_count()))
|
pool = Pool(min(len(engines_list), MAX_THREADS))
|
||||||
pool.map(run_search, ([globals()[engine], what, cat] for engine in engines_list))
|
pool.map(run_search, ([globals()[engine], what, cat] for engine in engines_list))
|
||||||
else:
|
else:
|
||||||
map(run_search, ([globals()[engine], what, cat] for engine in engines_list))
|
map(run_search, ([globals()[engine], what, cat] for engine in engines_list))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#VERSION: 1.40
|
#VERSION: 1.41
|
||||||
|
|
||||||
# Author:
|
# Author:
|
||||||
# Fabien Devaux <fab AT gnux DOT info>
|
# Fabien Devaux <fab AT gnux DOT info>
|
||||||
|
@ -34,12 +34,17 @@
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from os import path, cpu_count
|
from os import path
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from multiprocessing import Pool
|
from multiprocessing import Pool, cpu_count
|
||||||
|
|
||||||
THREADED = True
|
THREADED = True
|
||||||
|
try:
|
||||||
|
MAX_THREADS = cpu_count()
|
||||||
|
except NotImplementedError:
|
||||||
|
MAX_THREADS = 1
|
||||||
|
|
||||||
CATEGORIES = {'all', 'movies', 'tv', 'music', 'games', 'anime', 'software', 'pictures', 'books'}
|
CATEGORIES = {'all', 'movies', 'tv', 'music', 'games', 'anime', 'software', 'pictures', 'books'}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -168,7 +173,7 @@ def main(args):
|
||||||
what = urllib.parse.quote(' '.join(args[2:]))
|
what = urllib.parse.quote(' '.join(args[2:]))
|
||||||
if THREADED:
|
if THREADED:
|
||||||
#child process spawning is controlled min(number of searches, number of cpu)
|
#child process spawning is controlled min(number of searches, number of cpu)
|
||||||
with Pool(min(len(engines_list), cpu_count())) as pool:
|
with Pool(min(len(engines_list), MAX_THREADS)) as pool:
|
||||||
pool.map(run_search, ([globals()[engine], what, cat] for engine in engines_list))
|
pool.map(run_search, ([globals()[engine], what, cat] for engine in engines_list))
|
||||||
else:
|
else:
|
||||||
#py3 note: map is needed to be evaluated for content to be executed
|
#py3 note: map is needed to be evaluated for content to be executed
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue