当前我有以下代码:
# Open a place holding output file
with open('out.txt', 'w') as f:
# Run BOLSIG-
r = Popen("%s %s" % (bolsig, infile), stdout=f, cwd=outputdir)
# Wait for BOLSIG- to complete
Popen.wait(r)
# Remove the created output file as it is not used and BOLSIG- creates it's own file
remove('out.txt')
它需要一个.exe文件(bolsig)并运行其程序,然后将一个文件名(infile)输入到正在运行的程序中,然后程序会打开并相应执行输出自己的文件。该脚本通常与多达1000个输入文件一起运行。
我可以让Popen允许 bolsig 保存其输出文件的唯一方法是创建一个“保存”文件 out.txt ,然后将其删除。通常这可以正常工作,但有时程序会运行输出80/90/100文件,然后突然中断该行,
with open('out.txt', 'w') as f:
将引发以下错误,
Traceback (most recent call last):
File "C:/Users/minec/Desktop/College/4th_Year/Final Year Project/Program/Master-Program.py", line 1129, in <module>
main()
File "C:/Users/minec/Desktop/College/4th_Year/Final Year Project/Program/Master-Program.py", line 45, in main
outputdir = bolsig_minus(runfilelist)
File "C:/Users/minec/Desktop/College/4th_Year/Final Year Project/Program/Master-Program.py", line 496, in bolsig_minus
with open('out.txt', 'w') as f:
PermissionError: [Errno 13] Permission denied: 'out.txt'
有人知道为什么它偶尔会抛出此错误吗?如果是这样,我该如何解决它或修改代码以完全不使用 out.txt 文件,但仍然允许Popen保存它的文件?
答案 0 :(得分:0)
似乎您不时尝试在完全删除之前写信master
。您可以做什么:
out.txt
time.sleep()
之前检查out.txt
是否不存在我认为最好的方法是将数字3与数字2相结合。