"Tino Dai" <[EMAIL PROTECTED]> 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 > get > 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 the method itself of course! Thus you need a try/except in the driver section of your code and you need to do a raise in the implementation section after writing to sys.stdout... > Driver Section: > ap=apacheModule.apacheModule(configXML,putInDB="1") > while 1: > rVs=ap.perf() > 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 totally clear where the crash occurs). > Class Section (apacheModule module): > > def perf(self): > <..stuff deleted..> > self.putMethod: 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: if self.putMethod: I'm assuming an if statement given what follows... > # putMethod is a variable controlled by an XML file, > assume > 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 information needed to repair the damage or move onto the next data item(aka datum)? > else: > return self.parse(lines) > > def put(self,rVs): > <..stuff deleted> > try: > > (totalAccess,totalTraffic)=(rVs[3][1],self.sizeConvert > (rVs[3][3],rVs[3][4])) > > (userUsage,sysUsage,cuserUsage,csysUsage,cpuLoad)=(rVs[4][1],rVs[4][2],rVs[4][3],rVs[4][4],rVs[4][6]) > (requestsSec,bandwidth,perRequest)=(rVs[5][0], > self.sizeConvert(rVs[5][1],rVs[5][2]),self.sizeConvert(rVs[5][3],rVs[5][4])) > (requestsProc,idle)=(rVs[6][0],rVs[6][1]) > except Exception,e: > datetime.datetime.now() > sys.stdout.write(str(e) + "\n") > sys.stdout.write(rVs) > <..stuff deleted..> You need to add a raise here to force the exception up to the next level of detection. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor