Skip to content

Instantly share code, notes, and snippets.

@piksel
Created September 26, 2013 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piksel/6715377 to your computer and use it in GitHub Desktop.
Save piksel/6715377 to your computer and use it in GitHub Desktop.
Code to restart the python script if it gets an OOM exception. Yes, this is the wrong way to handle memory leaks, but unfortunately they sometimes occur in libraries out of your control.
try:
main()
except MemoryError, e:
print("Out of memory! Restarting proces...")
os.execl(sys.executable, *([sys.executable]+sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment