Skip to content

Instantly share code, notes, and snippets.

@axpence
Last active October 12, 2015 06:58
Show Gist options
  • Select an option

  • Save axpence/e1b3d48c00fe49e6af49 to your computer and use it in GitHub Desktop.

Select an option

Save axpence/e1b3d48c00fe49e6af49 to your computer and use it in GitHub Desktop.
import os
import signal
import subprocess
import time
import psutil
# The os.setsid() is passed in the argument preexec_fn so
# it's run after the fork() and before exec() to run the shell.
def kill_this_thing(proc_pid):
process = psutil.Process(proc_pid)
for proc in process.get_children(recursive=True):
proc.kill()
process.kill()
try:
os.system('cd /root/flask_only_app && gunicorn --bind 0.0.0.0:5000 wsgi')
os.system('beanstalkd -l 127.0.0.1 -p 11301')
time.sleep(2)
os.system('cd ~/yowsup-queue')
os.system('rm -r ~/.yowsup/')
time.sleep(2)
proc = subprocess.Popen('/usr/bin/python3 /root/yowsup-queue/run.py​'.split(),shell=True)
# time.sleep(10)
try:
proc.wait(timeout=10)
except subprocess.TimeoutExpired:
kill_this_thing(proc.pid)
os.system('python3 /root/yowsup-queue/run.py​')
except Exception as e:
print('send myself email here...')
except:
print('send myself email here...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment