Created
March 16, 2013 00:37
-
-
Save puentesarrin/5174314 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
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