【发布时间】:2013-05-07 18:23:21
【问题描述】:
我正在使用 subprocess 调用另一个程序并将其返回值保存到一个变量中。这个过程在循环中重复,几千次后程序崩溃并出现以下错误:
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
非常感谢任何想法如何解决这个问题!
由 cmets 提供的代码:
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”...您是否打开其他文件并将它们保存在列表中?
-
在运行 python 脚本之前,您是否尝试过
ulimit -Sn unlimited?
标签: python subprocess