From b3d52d467f900c05aac2d915069e27cb1fc1d2c1 Mon Sep 17 00:00:00 2001 From: zlsh80826 Date: Thu, 3 Nov 2022 10:16:09 +0800 Subject: [PATCH] Close popen pipe after used (#47053) --- python/paddle/fluid/core.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/python/paddle/fluid/core.py b/python/paddle/fluid/core.py index 718ddd4bd5..590d8e951f 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' -- GitLab