[Tutor] Restarting a module
alan.gauld at btinternet.com
Mon Jul 23 16:30:21 CEST 2007
"Tino Dai" <tinoloc at gmail.com> wrote
Your code confused me on several counts but in general...
> I have a question about restarting a part of the program after
> it dies.
> I have a driver program that instantiates a class and runs methods
> from that
> class. Occasionally, the method gets bad data and it bombs out.
> Instead of
> bombing out, I would like the program to grab new data and start the
> processing. I already have the try except block ready, but I'm
> unsure about
> how to restart the method itself. Is it just as easy as
> self.someMethod() or
> do I need to do something to the namespace to insure that I don't
> leakage from the past running of the method.
You generally can just call the method, there should be no "leakage"
because you are not reloading the module just accessing one of its
attributes - the method. Restart from the calling function not from
method itself of course! Thus you need a try/except in the driver
of your code and you need to do a raise in the implementation section
after writing to sys.stdout...
> Driver Section:
> while 1:
> for anObj in self.objList:
Not sure what the last line signifies but you need to wrap the
call to perf() in a try/except (if its perf that is failing - its not
clear where the crash occurs).
> Class Section (apacheModule module):
> def perf(self):
> <..stuff deleted..>
This is nonsensical syntax wise I have no idea what you are trying
to suggest. Is it a call to self.putMetthod()? Or is it a branch:
I'm assuming an if statement given what follows...
> # putMethod is a variable controlled by an XML file,
> this is always true
> return self.put(self.parse(lines))
If its put() that fails you could put the try/except here instead
of the driver section. The question is whether you have the
needed to repair the damage or move onto the next data item(aka
> return self.parse(lines)
> def put(self,rVs):
> <..stuff deleted>
> except Exception,e:
> sys.stdout.write(str(e) + "\n")
> <..stuff deleted..>
You need to add a raise here to force the exception up to
the next level of detection.
Author of the Learn to Program web site
More information about the Tutor