PyCon lightning talk on my Toro module for Tornado

Toro



Synchronization Primitives for
      Tornado Coroutines
Vanilla Tornado
class AsyncHandler(RequestHandler):
    @asynchronous
    def get(self):
        http_client = AsyncHTTPClient()
        http_client.fetch("http://example.com",
                          callback=self.on_fetch)

    def on_fetch(self, response):
        do_something_with_response(response)
        self.render("template.html")
tornado.gen
class GenAsyncHandler(RequestHandler):
    @asynchronous
    @gen.engine
    def get(self):
        http_client = AsyncHTTPClient()
        response = yield gen.Task(
            http_client.fetch, "http://example.com")
        do_something_with_response(response)
        self.render("template.html")
Great!
So where are:
• Lock
• Semaphore
• Condition
• Event
• Queue
Queues


A producer-consumer example
q = toro.JoinableQueue(maxsize=3)

@gen.engine
def producer():
    for item in range(10):
        print 'Sending', item
        yield gen.Task(q.put, item)

@gen.engine
def consumer():
    while True:
        item = yield gen.Task(q.get)
        print 'tt', 'Got', item
        q.task_done()

producer()
consumer()
loop = ioloop.IOLoop.instance()
# block until all tasks are done
q.join(callback=loop.stop)
loop.start()
$ python examples/producer_consumer_example.py
Sending 0
Sending 1
Sending 2
Sending 3
! ! Got 0
! ! Got 1
! ! Got 2
! ! Got 3
Sending 4
! ! Got 4
Sending 5
! ! Got 5
Sending 6
! ! Got 6
Sending 7
! ! Got 7
Sending 8
! ! Got 8
Sending 9
! ! Got 9
$
toro.rtfd.org



   A. Jesse Jiryu Davis
           10gen
     @jessejiryudavis
1 of 8

More Related Content

What's hot(20)

AsyncioAsyncio
Asyncio
Andrew Svetlov2.6K views
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
Shmuel Fomberg3.3K views
Introduction to asyncioIntroduction to asyncio
Introduction to asyncio
Saúl Ibarra Corretgé6.6K views
XpUg Coding Dojo: KataYahtzee in Ocp wayXpUg Coding Dojo: KataYahtzee in Ocp way
XpUg Coding Dojo: KataYahtzee in Ocp way
Giordano Scalzo5.5K views
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
Ramesh Nair4.4K views
TextileTextile
Textile
Vanessa Lošić427 views
Agile Iphone DevelopmentAgile Iphone Development
Agile Iphone Development
Giordano Scalzo3.1K views
Kotlin Coroutines. Flow is comingKotlin Coroutines. Flow is coming
Kotlin Coroutines. Flow is coming
Kirill Rozov3.3K views
Python Async IO HorizonPython Async IO Horizon
Python Async IO Horizon
Lukasz Dobrzanski3.4K views
C to perl bindingC to perl binding
C to perl binding
Shmuel Fomberg2.5K views
asyncio internalsasyncio internals
asyncio internals
Saúl Ibarra Corretgé8.2K views
node ffinode ffi
node ffi
偉格 高3K views
AnyeventAnyevent
Anyevent
Marian Marinov1.1K views
Go ConcurrencyGo Concurrency
Go Concurrency
jgrahamc14.3K views
Golang ChannelsGolang Channels
Golang Channels
Joris Bonnefoy701 views

Viewers also liked(20)

Map of empathyMap of empathy
Map of empathy
Felipe Vitorio336 views
Euskal Herriko hiriburuakEuskal Herriko hiriburuak
Euskal Herriko hiriburuak
iranjulienara471 views
Mit2 092 f09_lec23Mit2 092 f09_lec23
Mit2 092 f09_lec23
Rahman Hakim468 views
Wed thurs reformWed thurs reform
Wed thurs reform
Travis Klein403 views
AngelfallsAngelfalls
Angelfalls
Chandan Dubey316 views
BbfcBbfc
Bbfc
harryronchetti553 views
2009 india presentation   times2009 india presentation   times
2009 india presentation times
Chandan Dubey3K views
20120827maru scaleout seminar20120827maru scaleout seminar
20120827maru scaleout seminar
Maco Yoshioka519 views
AwesomeAwesome
Awesome
Chandan Dubey268 views
Advice of warren buffetAdvice of warren buffet
Advice of warren buffet
Chandan Dubey369 views
Magazine pitchMagazine pitch
Magazine pitch
ChloeMateides261 views
YourpreziYourprezi
Yourprezi
colera Vh284 views
Target audience researchTarget audience research
Target audience research
harryronchetti212 views
Congrats Siba  Congrats Siba
Congrats Siba
Mohammed Shuhuraab346 views
Apresentação java ioApresentação java io
Apresentação java io
Silvino Neto1.2K views
Tues treaty of versaillesTues treaty of versailles
Tues treaty of versailles
Travis Klein720 views
Frutos da Beneficência CristãFrutos da Beneficência Cristã
Frutos da Beneficência Cristã
João Carlos233 views

Similar to PyCon lightning talk on my Toro module for Tornado(20)

Async programming and pythonAsync programming and python
Async programming and python
Chetan Giridhar4.3K views
Nginx + Tornado = 17k req/sNginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/s
moret19799.8K views
Gevent what's the pointGevent what's the point
Gevent what's the point
seanmcq6.9K views
Principles of the Play frameworkPrinciples of the Play framework
Principles of the Play framework
Bernhard Huemer917 views
Distributed load testing with k6Distributed load testing with k6
Distributed load testing with k6
Thijs Feryn604 views
JavaScript PromisesJavaScript Promises
JavaScript Promises
L&T Technology Services Limited4.6K views
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
Garrett Welson599 views
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
Bo-Yi Wu22.3K views
Android dev 3Android dev 3
Android dev 3
Aravindharamanan S126 views
Flask patternsFlask patterns
Flask patterns
it-people7.3K views
Android webservicesAndroid webservices
Android webservices
Krazy Koder3.5K views
TornadowebTornadoweb
Tornadoweb
Osman Yuksel2.3K views

Recently uploaded(20)

ThroughputThroughput
Throughput
Moisés Armani Ramírez31 views
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh36 views
ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web Developers
Maximiliano Firtman161 views
Liqid: Composable CXL PreviewLiqid: Composable CXL Preview
Liqid: Composable CXL Preview
CXL Forum120 views

PyCon lightning talk on my Toro module for Tornado