Created
October 3, 2013 13:54
-
-
Save mitgr81/6810201 to your computer and use it in GitHub Desktop.
Simple flask app that kills itself after storing and returning a value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Process | |
import flask | |
app = flask.Flask(__name__) | |
autokill_time = 0 | |
thing_i_was_sent = '' | |
@app.route('/kill') | |
def seppuku(output_string="Farewell cruel world!"): | |
def hotout(): | |
raise RuntimeError('Not running with the Werkzeug Server') | |
flask.request.environ.get('werkzeug.server.shutdown', hotout)() | |
return output_string | |
@app.route('/', methods=["GET", "POST"]) | |
def handle_it(): | |
global thing_i_was_sent | |
if flask.request.method == 'GET': | |
if thing_i_was_sent: | |
return seppuku(thing_i_was_sent) | |
thing_i_was_sent = flask.request.data | |
return "I either just got something from you or I've got nothing for you." | |
if __name__ == '__main__': | |
server = Process(target=app.run, kwargs={'host': '0.0.0.0', 'port': 5555, 'debug': False}) | |
server.start() | |
print("You can see this") | |
if autokill_time: | |
print("This server will self-destruct in {} seconds. (unless you destroy it by going to /kill)".format(autokill_time)) | |
from time import sleep | |
sleep(autokill_time) | |
server.terminate() | |
server.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment