Created
February 22, 2012 14:21
-
-
Save bwghughes/1885327 to your computer and use it in GitHub Desktop.
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
""" | |
server.py | |
""" | |
from gevent import monkey | |
monkey.patch_all() | |
from time import sleep, time | |
import bottle | |
from bottle import route, run | |
@route('/stream') | |
def stream(): | |
yield make_message() | |
sleep(3) | |
yield make_message() | |
sleep(5) | |
yield make_message() | |
def make_message(): | |
return 'a_message' | |
bottle.debug(True) | |
run(host='0.0.0.0', port=8080, server='gevent') | |
""" | |
client.py | |
""" | |
import requests | |
import sys | |
r = requests.get('http://localhost:8080/stream') | |
for line in r.iter_lines(): | |
#if line: | |
sys.stdout.write(line) | |
sys.stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment