我有以下功能,它已经运行了好几个月。我没有更新我的Python版本(除非它发生在幕后?)。为什么python不再等待os.system完成?
def Blast(type, protein_sequence, start, end, genomic_sequence):
result = []
M = re.search('M', protein_sequence)
if M:
query = protein_sequence[M.start():]
temp = open("temp.ORF", "w")
print >>temp, '>blasting'
print >>temp, query
temp.close()
cline = blastp(query="'temp.ORF'", db="DB.blast.txt",
evalue=0.01, outfmt=5, out=type + ".BLAST")
os.system(str(cline))
blast_out = open(type + ".BLAST")
string = str(blast_out.read())
DEF = re.search("<Hit_def>((E|L)\d)</Hit_def>", string)
我收到blast_out=open(type+".BLAST")
找不到指定文件的错误。该文件被创建为os.system
调用所调用的程序输出的一部分。这通常需要大约30秒左右才能完成。但是,当我尝试运行该程序时,它会立即发出上面提到的错误。
我以为os.system()
应该等待完成?
我应该以某种方式强制等待吗? (我不想硬编码等待时间)。
编辑: 我已经在命令行版本的BLAST程序中运行了cline输出。一切似乎都很好。
尝试在'system'和'open'之间加入60秒的等待时间。如果问题仍然存在,那么外部程序以某种方式失败 –
您也可以从os.system调用中打印出返回值,这应指示程序是否失败。通常是:0 =确定; > 0 = not OK –
此外,请考虑使用['subprocess'](http://docs.python.org/2/library/subprocess.html) - 它具有更好的处理系统调用产生的错误的能力,并且通常应该用[代替'os.system'](http://docs.python.org/2/library/subprocess.html#replacing-os-system)。 –