我使用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
任何解决这个问题的办法都是非常感谢的!
注释提供的代码:
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()
我想问题是因为我正在处理一个带有子进程的打开文件:
这里的cmd变量包含刚创建但未关闭的文件的名称。然后
subprocess.Popen
调用该文件的系统命令。在多次执行此操作后,程序因该错误消息而崩溃。所以我从中学到的信息是
在Mac OSX(El Capitan)中,请参阅当前配置:
将“打开文件”的值设置为10K:
验证结果:
您可以尝试提高操作系统的打开文件限制:
ulimit -n 2048
相关问题 更多 >
编程相关推荐