Python调用linux 命令pvs时提示:File descriptor 3 () leaked on pvs invocation,代码及具体情况如下:
def execCmd(cmd):
r = os.popen(cmd)
text = r.read()
r.close()
return text
pvs_tmp=open(PVS_TMP,'w')
pvs_result=execCmd("pvs")
pvs_tmp.write(pvs_result)
……
报错:
File descriptor 4 (/patrol/scripts/getlun/20180925-095326tmp.txt) leaked on pvs invocation. Parent PID 72193: python
处理方式:
将命令调用方式改为:subprocess
process = subprocess.Popen("pvs", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
pvs_result = process.stdout.read().decode('utf-8')
更改后,提示信息消失,具体原因正在分析,后续更新……