Skip to content

Instantly share code, notes, and snippets.

@puentesarrin
Created March 16, 2013 00:37
Show Gist options
  • Save puentesarrin/5174314 to your computer and use it in GitHub Desktop.
Save puentesarrin/5174314 to your computer and use it in GitHub Desktop.
import toro
from tornado import ioloop, gen, web
q = toro.JoinableQueue()
@gen.engine
def consumer():
while True:
item = yield gen.Task(q.get)
try:
print 'Consuming', item
finally:
q.task_done()
@gen.engine
def producer():
for item in range(100000):
print 'Producing', item
yield gen.Task(q.put, item)
def on_queue_joined():
print 'Queue joined'
class MainHandler(web.RequestHandler):
def get(self):
self.write("Hello, world")
def app():
application = web.Application([
(r"/", MainHandler),
])
application.listen(8888)
@gen.engine
def main():
app()
consumer()
#q.join(callback=on_queue_joined)
yield gen.Task(q.join)
producer()
if __name__ == "__main__":
main()
loop = ioloop.IOLoop.instance()
loop.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment