Skip to content

Instantly share code, notes, and snippets.

@athoune
Created September 28, 2020 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athoune/03e84a7412519d7e403e9065ce16ca38 to your computer and use it in GitHub Desktop.
Save athoune/03e84a7412519d7e403e9065ce16ca38 to your computer and use it in GitHub Desktop.
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