Skip to content

Instantly share code, notes, and snippets.

@EntityReborn
Created May 1, 2011 20:42
Show Gist options
  • Save EntityReborn/950857 to your computer and use it in GitHub Desktop.
Save EntityReborn/950857 to your computer and use it in GitHub Desktop.
bootstrap for a restartable python process.
# The only requirements are that the process ends with a specific return code (7 in this case)
import os
import sys
import subprocess
class main(object):
def __init__(self, file, cwd):
self.file = os.path.abspath(file)
self.cwd = os.path.abspath(cwd)
def run(self):
restart = True
while restart:
run = subprocess.Popen([sys.executable, self.file], cwd=self.cwd)
retn = run.wait()
if retn != 7:
restart = False
m = main("botmain.py", ".")
m.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment