在纠正错误后恢复程序的执行 [英] Resuming a program's execution after correcting error
问题描述
嗨。
有没有人知道如果错误更正后是否可以在错误点恢复python脚本
?
如果我每次都必须从
scratch重新启动,我有一个大型程序需要永远。错误是写入文件的数据,所以如果所有数据都丢失了,那么它似乎很浪费,必须重新计算。
此致,
Sheldon
Sheldon写道:
嗨。
有没有人知道在错误发生后是否可以在错误点恢复python脚本
?
如果我每次都要从
刮开,我有一个大型程序需要永远。错误是写入文件的数据所以如果所有数据丢失并且必须再次重新计算,那么它似乎是浪费。
正如我之前所说,这可以通过找出引发错误的位置来完成,
原因是什么,并插入一个适当的try-except-statement在
代码中。
如果程序本身没有修改代码就没有办法做到这一点/>
并不提供这样的选择。
Georg
Sheldon写道:
有没有人知道是否可以在错误点恢复python脚本
更正错误后?
我有如果我必须每次从
刮开重启,那么这个大程序需要永远。错误是写入文件的数据所以如果所有数据丢失并且必须再次重新计算,那么它似乎是浪费。
可能你可以把一些参数放到你的主循环中:
start_point =开始
如果start_point == begin:output = open(''outputfile'',''w'')
else:output = open(''outputfile'',''a'')
而start_point< = case< = end_point:
试试:
do_complex_computation(case)
除了例外:
打印盒
破解
如果您收到错误,则修复程序并设置
start_point = case
继续使用该程序。
Tuomas
Sheldon写道:
嗨。
有谁知道是否有人知道错误更正后,可以在错误点恢复python脚本
?
如果我必须从
重启,我有一个大的程序需要永远每次
刮刮。错误是写入文件的数据所以如果所有数据丢失并且必须再次重新计算,那么它似乎是浪费。
Afaik,你能做的最好的就是用python -i运行脚本,
会给你一个互动的提示从中您可以访问
模块级变量。或者甚至更好,用小的
数据集测试你的脚本,并且只有在你修复了任何明显的错误之后才进行真正的计算。
Hi.
Does anyone know if one can resume a python script at the error point
after the error is corrected?
I have a large program that take forever if I have to restart from
scratch everytime. The error was the data writing a file so it seemed
such a waste if all the data was lost and must be recalculated again.
Sincerely,
Sheldon
Sheldon wrote:Hi.
Does anyone know if one can resume a python script at the error point
after the error is corrected?
I have a large program that take forever if I have to restart from
scratch everytime. The error was the data writing a file so it seemed
such a waste if all the data was lost and must be recalculated again.As I said before, this can be done by finding out where the error is raised,
what the cause is and by inserting an appropriate try-except-statement in
the code.
There''s no way to do that without modifying the code, if the program itself
doesn''t offer such an option.
Georg
Sheldon wrote:Does anyone know if one can resume a python script at the error point
after the error is corrected?
I have a large program that take forever if I have to restart from
scratch everytime. The error was the data writing a file so it seemed
such a waste if all the data was lost and must be recalculated again.May be you could put some parameter to your main loop:
start_point=begin
if start_point==begin: output=open(''outputfile'', ''w'')
else : output=open(''outputfile'', ''a'')
while start_point <= case <= end_point:
try:
do_complex_computation(case)
except Exception:
print case
break
If you get an error you repair the program and set
start_point=case
and go on with the program.
Tuomas
Sheldon wrote:Hi.
Does anyone know if one can resume a python script at the error point
after the error is corrected?
I have a large program that take forever if I have to restart from
scratch everytime. The error was the data writing a file so it seemed
such a waste if all the data was lost and must be recalculated again.Afaik, the best you can do is run the script with "python -i", which
will give you an interactive prompt from which you have access to the
module-level variables. Or even better, test your script with small
data sets, and do the real calculations only after you''ve fixed any
obvious bugs.
这篇关于在纠正错误后恢复程序的执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!