Skip to content

Commit

Permalink
#2064: move get_cpu_count to os_util so we can re-use it
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@21113 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Nov 27, 2018
1 parent 8187200 commit 2b4c0ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/xpra/codecs/vpx/encoder.pyx
Expand Up @@ -14,7 +14,7 @@ from xpra.log import Logger
log = Logger("encoder", "vpx")

from xpra.codecs.codec_constants import video_spec
from xpra.os_util import bytestostr, WIN32, OSX, POSIX
from xpra.os_util import get_cpu_count, bytestostr, WIN32, OSX, POSIX
from xpra.util import AtomicInteger, envint, envbool
from xpra.buffers.membuf cimport object_as_buffer

Expand All @@ -24,17 +24,7 @@ from xpra.monotonic_time cimport monotonic_time

SAVE_TO_FILE = os.environ.get("XPRA_SAVE_TO_FILE")

#sensible default:
cpus = 2
try:
cpus = os.cpu_count()
except:
try:
import multiprocessing
cpus = multiprocessing.cpu_count()
except:
pass
cdef int VPX_THREADS = envint("XPRA_VPX_THREADS", max(1, cpus-1))
cdef int VPX_THREADS = envint("XPRA_VPX_THREADS", max(1, get_cpu_count()-1))

cdef inline int roundup(int n, int m):
return (n + m - 1) & ~(m - 1)
Expand Down
15 changes: 15 additions & 0 deletions src/xpra/os_util.py
Expand Up @@ -367,6 +367,21 @@ def get_generic_os_name():
return v
return sys.platform

def get_cpu_count():
#sensible default:
cpus = 2
try:
try:
#python3:
cpus = os.cpu_count()
except AttributeError:
#python2:
import multiprocessing
cpus = multiprocessing.cpu_count()
except:
pass
return cpus


def load_binary_file(filename):
if not os.path.exists(filename):
Expand Down

0 comments on commit 2b4c0ce

Please sign in to comment.