Last active
April 19, 2017 17:09
-
-
Save pfig/7c035f60feeed82d5edd00a0bc35dc4c to your computer and use it in GitHub Desktop.
HTTP server producing a stream of RecordIO data
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
# | |
# Run with gunicorn -k eventlet server:app | |
# | |
# Dependencies: | |
# eventlet==0.21.0 | |
# Flask==0.12.1 | |
# gunicorn==19.7.1 | |
# | |
import time | |
import random | |
from flask import Flask, Response | |
import eventlet | |
eventlet.monkey_patch() | |
subjects = ['Alice', 'Bob', 'Eve'] | |
verbs = ['eats', 'steals', 'paints'] | |
objects = ['an apple', 'cookies', 'the elephant'] | |
app = Flask('chunky_bacon') | |
@app.route('/stream') | |
def record_io_stream(): | |
def generate(): | |
total = 0 | |
while (total <= 200): | |
output = '{} {} {}'.format( | |
random.choice(subjects), | |
random.choice(verbs), | |
random.choice(objects)) | |
much = len(output) | |
output = '{}\n{}'.format(much, output) | |
total += much | |
yield output | |
time.sleep(1) | |
return Response(generate(), mimetype='text/plain') | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment