Browse Source

[search engine] Fix cpu_count in old Python versions

adaptive-webui-19844
ngosang 9 years ago
parent
commit
32c813eece
  1. 9
      src/searchengine/nova/nova2.py
  2. 13
      src/searchengine/nova3/nova2.py

9
src/searchengine/nova/nova2.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#VERSION: 1.40
#VERSION: 1.41
# Author:
# Fabien Devaux <fab AT gnux DOT info>
@ -41,6 +41,11 @@ from multiprocessing import Pool, cpu_count @@ -41,6 +41,11 @@ from multiprocessing import Pool, cpu_count
from fix_encoding import fix_encoding
THREADED = True
try:
MAX_THREADS = cpu_count()
except NotImplementedError:
MAX_THREADS = 1
CATEGORIES = {'all', 'movies', 'tv', 'music', 'games', 'anime', 'software', 'pictures', 'books'}
################################################################################
@ -170,7 +175,7 @@ def main(args): @@ -170,7 +175,7 @@ def main(args):
if THREADED:
#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))
else:
map(run_search, ([globals()[engine], what, cat] for engine in engines_list))

13
src/searchengine/nova3/nova2.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#VERSION: 1.40
#VERSION: 1.41
# Author:
# Fabien Devaux <fab AT gnux DOT info>
@ -34,12 +34,17 @@ @@ -34,12 +34,17 @@
# POSSIBILITY OF SUCH DAMAGE.
import urllib.parse
from os import path, cpu_count
from os import path
from glob import glob
from sys import argv
from multiprocessing import Pool
from multiprocessing import Pool, cpu_count
THREADED = True
try:
MAX_THREADS = cpu_count()
except NotImplementedError:
MAX_THREADS = 1
CATEGORIES = {'all', 'movies', 'tv', 'music', 'games', 'anime', 'software', 'pictures', 'books'}
################################################################################
@ -168,7 +173,7 @@ def main(args): @@ -168,7 +173,7 @@ def main(args):
what = urllib.parse.quote(' '.join(args[2:]))
if THREADED:
#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))
else:
#py3 note: map is needed to be evaluated for content to be executed

Loading…
Cancel
Save