我正在使用子進程來調用另一個程序並將其返回值保存到一個變量。重複這個過程,在一個循環中,經過了幾十萬次的程序崩潰並出現以下錯誤:Python子進程:太多打開文件
Traceback (most recent call last):
File "./extract_pcgls.py", line 96, in <module>
SelfE.append(CalSelfEnergy(i))
File "./extract_pcgls.py", line 59, in CalSelfEnergy
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
File "/usr/lib/python3.2/subprocess.py", line 745, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.2/subprocess.py", line 1166, in _execute_child
errpipe_read, errpipe_write = _create_pipe()
OSError: [Errno 24] Too many open files
不知道如何來解決這個問題,非常感謝!從意見提供
代碼:
cmd = "enerCHARMM.pl -parram=x,xtop=topology_modified.rtf,xpar=lipid27_modified.par,nobuildall -out vdwaals {0}".format(cmtup[1])
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
out, err = p.communicate()
Communicate()關閉管道,所以這不是你的問題。最後,Popen()只是當你用盡管道時碰巧運行的命令......問題可能在代碼中的其他地方,其他文件保持打開狀態。我注意到「SelfE.append」...你打開其他文件並將它們保存在列表中嗎? – tdelaney 2013-05-13 17:38:17