Skip to content

Instantly share code, notes, and snippets.

@athoune
Created Sep 28, 2020
Embed
What would you like to do?
Route to healthy server
#!/usr/bin/env python3
import signal
import os
from flask import Flask, abort
from werkzeug.serving import run_simple
state = True
def handler(*args):
global state
state = not state
print("swap to %s" % state)
signal.signal(signal.SIGHUP, handler)
app = Flask(__name__)
@app.route('/')
def hello_world():
if state:
return 'Hello, World!'
else:
abort(500)
if __name__ == '__main__':
run_simple('0.0.0.0', 5000, app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment