Gevent
def __iter__(self):
threads = []
def events(queue, listener):
for m in listener:
print "Yielding: %s" % ("event: %s\ndata: %s\n\n" % ("message", m['data']))
queue.put("event: %s\ndata: %s\n\n" % ("message", m['data']))
gevent.sleep(0.1)
def keepalive(queue):
while True:
print "keepalive"
queue.put(": ping\n\n")
gevent.sleep(25)
self.threads.append(gevent.spawn(events, self.queue, self.listener))
self.threads.append(gevent.spawn(keepalive, self.queue))
while True:
yield self.queue.get()
*Server-Sent Events on Heroku