Refactor automatic cpu detection code to auto_detect_cpus()
This commit is contained in:
@@ -4,27 +4,31 @@ import py
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def auto_detect_cpus():
|
||||||
|
try:
|
||||||
|
from os import sched_getaffinity
|
||||||
|
except ImportError:
|
||||||
|
if os.environ.get('TRAVIS') == 'true':
|
||||||
|
# workaround https://bitbucket.org/pypy/pypy/issues/2375
|
||||||
|
return 2
|
||||||
|
try:
|
||||||
|
from os import cpu_count
|
||||||
|
except ImportError:
|
||||||
|
from multiprocessing import cpu_count
|
||||||
|
else:
|
||||||
|
def cpu_count():
|
||||||
|
return len(sched_getaffinity(0))
|
||||||
|
|
||||||
|
try:
|
||||||
|
n = cpu_count()
|
||||||
|
except NotImplementedError:
|
||||||
|
return 1
|
||||||
|
return n if n else 1
|
||||||
|
|
||||||
|
|
||||||
def parse_numprocesses(s):
|
def parse_numprocesses(s):
|
||||||
if s == 'auto':
|
if s == 'auto':
|
||||||
try:
|
return auto_detect_cpus()
|
||||||
from os import sched_getaffinity
|
|
||||||
except ImportError:
|
|
||||||
if os.environ.get('TRAVIS') == 'true':
|
|
||||||
# workaround https://bitbucket.org/pypy/pypy/issues/2375
|
|
||||||
return 2
|
|
||||||
try:
|
|
||||||
from os import cpu_count
|
|
||||||
except ImportError:
|
|
||||||
from multiprocessing import cpu_count
|
|
||||||
else:
|
|
||||||
def cpu_count():
|
|
||||||
return len(sched_getaffinity(0))
|
|
||||||
|
|
||||||
try:
|
|
||||||
n = cpu_count()
|
|
||||||
except NotImplementedError:
|
|
||||||
return 1
|
|
||||||
return n if n else 1
|
|
||||||
else:
|
else:
|
||||||
return int(s)
|
return int(s)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user