Skip to content

Instantly share code, notes, and snippets.

@bwghughes
Created February 22, 2012 14:21
Show Gist options
  • Save bwghughes/1885327 to your computer and use it in GitHub Desktop.
Save bwghughes/1885327 to your computer and use it in GitHub Desktop.
"""
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