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 13 1708
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.
I don't know how much help this is going to be, but you could store
values in a temporary file on the hard disk and write checkpoints to
read in the data and begin from a point somewhere in the middle of the
script.
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.
Sincerely,
Sheldon
Georg Brandl wrote:
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.
I could be mistaken, but I *think* the OP is asking how to re-enter the
stack at the same point as the exception exited from and continue with
the execution as if the exception never happened. AFAIK, that isn't
possible; however, given that he has a file to work from that indicates
a portion of the state at the time of the exception, I think he may be
able simulate that kind of functionality by reading in the file on
exception and then returning a call to the function where the exception
occured with the data from the file. Something like this mockup:
def faulty_function(a, b, c=None):
if not c:
c = 0
try:
# modify c, write c to file...
# oops hit an exception
c += a / b
except:
# read from the file here
# c = ...
# and fix the error
b += 1
return faulty_function(a, b, c)
return c
print faulty_function(2, 0) # =2
Of course, it's probably much better to just fix the code and avoid the
exception in the first place. ;)
Regards,
Jordan
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.
You could modify the program while you're debugging it so that instead
of, say:
calculate data
write data
you have:
if saved data exists:
load data
else:
calculate data
save data
write data
The pickle module would be useful here.
Matthew
MonkeeSage wrote:
Georg Brandl wrote:
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.
I could be mistaken, but I *think* the OP is asking how to re-enter the
stack at the same point as the exception exited from and continue with
the execution as if the exception never happened. AFAIK, that isn't
possible; however, given that he has a file to work from that indicates
a portion of the state at the time of the exception, I think he may be
able simulate that kind of functionality by reading in the file on
exception and then returning a call to the function where the exception
occured with the data from the file. Something like this mockup:
def faulty_function(a, b, c=None):
if not c:
c = 0
try:
# modify c, write c to file...
# oops hit an exception
c += a / b
except:
# read from the file here
# c = ...
# and fix the error
b += 1
return faulty_function(a, b, c)
return c
print faulty_function(2, 0) # =2
Of course, it's probably much better to just fix the code and avoid the
exception in the first place. ;)
Regards,
Jordan
Thanks Jordon,
I think you understood my problem best. I know now that this is not
possible but I would like to create an exception that saves all the
current variables when there is an error. I think pickle is the answer
but I never got it to work. My program is very large and it is being
modified often.
Any advice on how to save the variables.
/Sheldon
MRAB wrote:
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.
You could modify the program while you're debugging it so that instead
of, say:
calculate data
write data
you have:
if saved data exists:
load data
else:
calculate data
save data
write data
The pickle module would be useful here.
Matthew
I like your idea Matthew but I don't know how to pickle the many
variables in one file. Do I need to pickle each and every variable into
a seperate file?
var1,var2
pickle.dump(var1,f)
pickle.dump(var2,f2)
/Sheldon
Sheldon wrote:
MRAB wrote:
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.
>
You could modify the program while you're debugging it so that instead
of, say:
calculate data
write data
you have:
if saved data exists:
load data
else:
calculate data
save data
write data
The pickle module would be useful here.
Matthew
I like your idea Matthew but I don't know how to pickle the many
variables in one file. Do I need to pickle each and every variable into
a seperate file?
var1,var2
pickle.dump(var1,f)
pickle.dump(var2,f2)
Using the 'pickle' module:
# To store:
f = open(file_path, "wb")
pickle.dump(var1, f)
pickle.dump(var2, f)
f.close()
# To load
f = open(file_path, "rb")
var1 = pickle.load(f)
var2 = pickle.load(f)
f.close()
A more flexible alternative is to use the 'shelve' module. This behaves
like a dict:
# To store
s = shelve.open(file_path)
s["var1"] = "first"
s["var2"] = [2, 3]
s.close()
# To load
s = shelve.open(file_path)
print s["var1"] # This prints "first"
print s["var2"] # This prints [2, 3]
s.close()
Hope that helps
Matthew
On 3 Oct 2006 16:58:17 -0700, MRAB <go****@mrabarnett.plus.comwrote:
I like your idea Matthew but I don't know how to pickle the many
variables in one file. Do I need to pickle each and every variable into
a seperate file?
var1,var2
pickle.dump(var1,f)
pickle.dump(var2,f2)
Using the 'pickle' module:
# To store:
f = open(file_path, "wb")
pickle.dump(var1, f)
pickle.dump(var2, f)
f.close()
# To load
f = open(file_path, "rb")
var1 = pickle.load(f)
var2 = pickle.load(f)
f.close()
A more flexible alternative is to use the 'shelve' module. This behaves
like a dict:
# To store
s = shelve.open(file_path)
s["var1"] = "first"
s["var2"] = [2, 3]
s.close()
# To load
s = shelve.open(file_path)
print s["var1"] # This prints "first"
print s["var2"] # This prints [2, 3]
s.close()
As long as we're on the subject of data serialization, I should like
to bring up PyYaml. YAML is a portable format for storing data of all
kinds; it became popular via Ruby I think, but there are
implementations for many other languages. If you stick to storing
simple stuff like lists, strings, and dictionaries, you can use your
YAML data almost anywhere, but PyYaml even supports reifying things
like lambdas.
MRAB wrote:
Sheldon wrote:
MRAB wrote:
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.
You could modify the program while you're debugging it so that instead
of, say:
>
calculate data
write data
>
you have:
>
if saved data exists:
load data
else:
calculate data
save data
write data
>
The pickle module would be useful here.
>
Matthew
I like your idea Matthew but I don't know how to pickle the many
variables in one file. Do I need to pickle each and every variable into
a seperate file?
var1,var2
pickle.dump(var1,f)
pickle.dump(var2,f2)
Using the 'pickle' module:
# To store:
f = open(file_path, "wb")
pickle.dump(var1, f)
pickle.dump(var2, f)
f.close()
# To load
f = open(file_path, "rb")
var1 = pickle.load(f)
var2 = pickle.load(f)
f.close()
A more flexible alternative is to use the 'shelve' module. This behaves
like a dict:
# To store
s = shelve.open(file_path)
s["var1"] = "first"
s["var2"] = [2, 3]
s.close()
# To load
s = shelve.open(file_path)
print s["var1"] # This prints "first"
print s["var2"] # This prints [2, 3]
s.close()
Hope that helps
Matthew
Perfect Matthew!
Much obliged!
/Sheldon
Sheldon wrote:
MRAB wrote:
>Sheldon wrote:
>>MRAB wrote: 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. >
Sorry if this is off-topic here but Dylan ( http://www.opendylan.org) is
a nice language (I sometimes like even more than python itself) that
allows you to continue the work right where the exception was thrown.
Henning
Henning Hasemann wrote:
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.
Sorry if this is off-topic here but Dylan (http://www.opendylan.org) is
a nice language (I sometimes like even more than python itself) that
allows you to continue the work right where the exception was thrown.
As I have explained before in this newsgroup, Xerox Parc had that
ability (the ability to finish an exception by returning to its source)
in their system implementation language, and finally removed the
capability when they saw how many bugs were related to its use.
--Scott David Daniels sc***********@acm.org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bruce W...1 |
last post by:
A scripting newbie question... I'm trying to understand some code I found.
This script conducts a poll and writes the results to a text file. The
following statement is part of the source file. ...
|
by: kajol |
last post by:
Hi
I am creating a setup project in VS.NET, I have "PluginInstaller.msi"
installed in my computer, When I am running this setup program in a test
machine where no .NET framework and MDAC2.7 is...
|
by: kimimaro |
last post by:
Is there anymore methods in exiting your program using pure C language
other than return 0?
|
by: Chris |
last post by:
I posted this in the C# language group, then thought it
might be more appropriate in this group. I would not
cross-post except I want the answer so badly.
I built small C# Web and Web Service...
|
by: mike |
last post by:
Sound problems resuming from Hibernation
I have an MP3 player that plays MP3s off DVD.
Uses mci sendstring
errreturn = mciSendString("play sound", rs, 128, cb)
Been working great for...
|
by: Odinn |
last post by:
Greetings , This is my first year at programming and 3rd week at this
so count me as a pure newbie.
I am trying to make a program that gets a number and prints out starts
as this:
For input 3 :...
|
by: Jothishankar |
last post by:
Hi,
I am new to c#. I am trying to build an application that does backup
of files to an external hard disk.
My application behaves strangely. When i run the application under
debug mode (F5),...
|
by: Jerry West |
last post by:
In VB6 one could use 'Resume Next' to have program execution resume at the
statement following where an error occurred. Is there something comparable
in VB .NET?
Try
i = 0 / 0
DoEvenMore
|
by: Sooraj |
last post by:
Hi,
I'm a mechanical engineer new to programming. I was trying to write a
program in Visual Basic Express Edition 2005. I want to run a file
using an application called madymo601 in command...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |