Skip to content

Commit 57ffc74

Browse files
committed
Guarded memcheck code
1 parent b2db4cc commit 57ffc74

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

setup.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,6 @@
99
from distutils.version import LooseVersion
1010

1111

12-
class memoryCheck():
13-
"""Checks memory of a given system"""
14-
15-
def __init__(self):
16-
17-
if os.name == "posix":
18-
self.value = self.linuxRam()
19-
else:
20-
self.value = -1
21-
22-
def linuxRam(self):
23-
"""Returns the RAM of a linux system"""
24-
totalMemory = os.popen("free -m").readlines()[1].split()[1]
25-
return int(totalMemory)
26-
27-
2812
class CMakeExtension(Extension):
2913
def __init__(self, name, sourcedir=''):
3014
Extension.__init__(self, name, sources=[])
@@ -59,24 +43,33 @@ def build_extension(self, ext):
5943
cfg = 'Debug' if self.debug else 'Release'
6044
build_args = ['--config', cfg]
6145

46+
# Memcheck (guard if it fails)
47+
totalMemory = 4000
48+
if platform.system() == "Linux":
49+
try:
50+
totalMemory = int(os.popen("free -m").readlines()[1].split()[1])
51+
except (KeyboardInterrupt, SystemExit):
52+
raise
53+
except:
54+
totalMemory = 4000
55+
6256
if platform.system() == "Windows":
6357
cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)]
6458
if sys.maxsize > 2**32:
6559
cmake_args += ['-A', 'x64']
6660
build_args += ['--', '/m']
6761
else:
6862
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
69-
63+
7064
#Memcheck
71-
M = memoryCheck()
72-
if M.value < 1000:
73-
build_args += ['--', '-j1']
65+
parallel_args = ['--', '-j']
66+
if totalMemory < 1000:
67+
parallel_args = ['--', '-j1']
7468
cmake_args += ['-DHUNTER_JOBS_NUMBER=1']
75-
elif M.value < 2000:
76-
build_args += ['--', '-j2']
69+
elif totalMemory < 2000:
70+
parallel_args = ['--', '-j2']
7771
cmake_args += ['-DHUNTER_JOBS_NUMBER=2']
78-
else:
79-
build_args += ['--', '-j']
72+
build_args += parallel_args
8073

8174
# Hunter configuration to release only
8275
cmake_args += ['-DHUNTER_CONFIGURATION_TYPES=Release']

0 commit comments

Comments
 (0)