It would be good to put this whole section into a <code>try:...</code> clause and put the "recovery" section into it's <code>finally:...</code>.  That way, no matter what recovery will always happen.