I have a problem to make my code more self-healable. Eg: I execute a method 1 to load the data from a CSV into the Vertica database. I have another method 2 to check if the number of rows in the database and the number of lines in CSV file is same. If the number of lines doesn't match, then I was thinking of calling the method 2 from the point where it called the query to load data from CSV into the database.
I was thinking of a checkpointing strategy for this problem. like, maintain some points in the code where the errors usually occur and recalling them at other points.
I already tried using pickle module in python, but came to know that pickle can only save objects, classes, variables etc. can't save the point from where I can actually execute a method.
i have provided some demo code:
import pickle
class Fruits:
def apple(self):
filehandler= open ("Fruits.obj","wb")
print "apple"
pickle.dump(self,filehandler)
print "mapple"
filehandler.close()
def mango(self):
filehandler = open("Fruits.obj","rb")
print "mango"
obj=pickle.load(filehandler)
obj.apple()
general = Fruits()
general.apple()
general.mango()
the output of above program is:
apple
mapple
mango
apple
mapple
I want my code to execute such that when mango method calls apple method, it must execute from the point of only print "mapple". it must not execute the whole method.
please do provide me some insight on how to solve this problem.
thanks in advance
Add a
if condidtion
todef apple
, you don't needpickle
at all.