I have some piece of python code which generates a MemoryError
after a while. I know that it consumes a lot of memory.
So, I decided to put the code within a try/except
block so that the skeleton looks like the following:
while True:
while True:
try:
#---- do some stuff
except MemoryError as err:
print(err)
break
So, my idea is to break out of the first while
-loop if a MemoryError
occurs and since I have an outer while
-loop, it will start the program again.
It seems that it works for the moment but I am not sure. After a while, it stops again and I need to restart the program again.
Does somebody know a better solution so that the program can run after the MemoryError
again?