Skip to content

Instantly share code, notes, and snippets.

@ikudriavtsev
Created March 12, 2014 20:46
Show Gist options
  • Save ikudriavtsev/9515925 to your computer and use it in GitHub Desktop.
Save ikudriavtsev/9515925 to your computer and use it in GitHub Desktop.
Graceful restart of gunicorn server
# the idea is taken from here: http://unicorn.bogomips.org/SIGNALS.html
import os
import signal
# first we need to get the master process id
# it might be stored in a .pid file, e.g.
# let's assume we have the id in `master_pid`
# sending USR2 signal to the master process, this will recreate the master process and the worker(s)
os.kill(master_pid, signal.SIGUSR2)
# sending WINCH signal to the old master process
# can be skipped if the process is not daemonized
os.kill(master_pid, signal.SIGWINCH)
# sending the QUIT signal to the old master process
os.kill(master_pid, signal.SIGQUIT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment