title: How to deal with "MemoryError" in Python code
body: <p>I have some piece of python code which generates a <code>MemoryError</code> after a while. I know that it consumes a lot of memory.
  So, I decided to put the code within a <code>try/except</code> block so that the skeleton looks like the following:</p>
  
  <pre><code>while True:
  
        while True:
  
              try:
              #---- do some stuff
  
              except MemoryError as err:
                     print(err)
                     break
  </code></pre>
  
  <p>So, my idea is to break out of the first <code>while</code>-loop if a <code>MemoryError</code> occurs and since I have an outer <code>while</code>-loop, it will start the program again.</p>
  
  <p>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 <code>MemoryError</code> again?</p>