Skip to content

Instantly share code, notes, and snippets.

@dukebody
dukebody / fabfile.py
Created October 28, 2015 11:14
Fabric task to restart gunicorn without downtime, killing workers sequentially, sleeping in between to let new ones get ready.
@task
def reloadapp(sleep=5):
"""
Reloads lead-ratings app and the celery workers.
"""
supervisorctl = os.path.join(env.venv_path, 'bin', 'supervisorctl')
# kill all gunicorn master children, sleeping in between
master_pid = run('sudo %s pid app' % supervisorctl)
children = run('pgrep -P %s' % master_pid).split('\r\n')
@dukebody
dukebody / json_field.py
Last active March 28, 2024 11:44
JSON field for WTForms that converts between the form string data and a dictionary representation, with validation
from wtforms import fields
import json
class JSONField(fields.StringField):
def _value(self):
return json.dumps(self.data) if self.data else ''
def process_formdata(self, valuelist):
if valuelist: