diff --git a/python/paddle/fluid/core.py b/python/paddle/fluid/core.py index 718ddd4bd56310d58362e38a231254f810090795..590d8e951f128ee644b19f106e572b896702d05a 100644 --- a/python/paddle/fluid/core.py +++ b/python/paddle/fluid/core.py @@ -73,7 +73,9 @@ def avx_supported(): has_avx = False if sysstr == 'linux': try: - has_avx = os.popen('cat /proc/cpuinfo | grep -i avx').read() != '' + pipe = os.popen('cat /proc/cpuinfo | grep -i avx') + has_avx = pipe.read() != '' + pipe.close() except Exception as e: sys.stderr.write( 'Can not get the AVX flag from /proc/cpuinfo.\n' @@ -82,10 +84,9 @@ def avx_supported(): return has_avx elif sysstr == 'darwin': try: - has_avx = ( - os.popen('sysctl machdep.cpu.features | grep -i avx').read() - != '' - ) + pipe = os.popen('sysctl machdep.cpu.features | grep -i avx') + has_avx = pipe.read() != '' + pipe.close() except Exception as e: sys.stderr.write( 'Can not get the AVX flag from machdep.cpu.features.\n'