diff --git a/python/paddle/fluid/core.py b/python/paddle/fluid/core.py index 3087a5a4b014262d5ff29a216395ab72d2e59e1e..1f26b3d0bf059e8077c8534c034f6b3bc89ab7d6 100644 --- a/python/paddle/fluid/core.py +++ b/python/paddle/fluid/core.py @@ -92,15 +92,14 @@ def avx_supported(): 'Can not get the AVX flag from machdep.cpu.features.\n' 'The original error is: %s\n' % cpt.get_exception_message(e)) if not has_avx: - try: - has_avx = os.popen( - 'sysctl machdep.cpu.leaf7_features | grep -i avx').read( - ) != '' - except Exception as e: - sys.stderr.write( - 'Can not get the AVX flag from machdep.cpu.leaf7_features.\n' - 'The original error is: %s\n' % - cpt.get_exception_message(e)) + import subprocess + pipe = subprocess.Popen( + 'sysctl machdep.cpu.leaf7_features | grep -i avx', + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + _ = pipe.communicate() + has_avx = True if pipe.returncode == 0 else False return has_avx elif sysstr == 'windows': import ctypes