SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Deferred Gratification
Patterns of asynchronous flow of control
with Twisted deferreds

Terry Jones
terry@fluidinfo.com
@terrycojones
Not an intro talk. Sorry!
• Assume you understand Deferreds
• Assume you understand async
Read defer.py
• Lots of people don’t
• Much of it is beautiful
• Deferreds seem cryptic
• They’re are actually very simple
Building blocks
    Simple functions that help with deferreds
•    succeed
•    fail
•    maybeDeferred

    Classes that build on simple deferreds
•   DeferredList
•   DeferredQueue
•   DeferredSemaphore
•   DeferredLock
Deferreds let you replace
synchronous data structures
 with elegant asynchronous
         equivalents
Some of our classes
http://jon.es/other/europython-2010-deferreds.tar.bz2


• tee
• RetryingCall
• DeferredPooler


                                     }
• ControllableDeferred
• DeferredPool                            rdq.py
• ResizableDispatchQueue
DeferredPooler
 client



 client      server   whatever



 client
DeferredPooler
 client   fe
            tc
               h(
                 x,
                    y)



 client                  server   whatever



 client
DeferredPooler
 client   fe
            tc
               h(
                 x,
                    y)


                                  fetch(x,y)
 client                  server                whatever



 client
DeferredPooler
 client   fe
            tc
               h(
                 x,
                    y)


          fetch(x,y)              fetch(x,y)
 client                  server                whatever



 client
DeferredPooler
 client   fe
            tc
                 h(
                   x,
                          y)


          fetch(x,y)                    fetch(x,y)
 client                        server                whatever
                       , y)
                  (   x
               ch
          f et

 client
DeferredPooler
 client   fe
            tc
                 h(
                   x,
                          y)


          fetch(x,y)                    fetch(x,y)
 client                        server                whatever
                                        result
                       , y)
                  (   x
               ch
          f et

 client
DeferredPooler
 client    fe
              tc
          re     h(
            su      x,
               lt      y)


           fetch(x,y)                fetch(x,y)
 client                     server                whatever
           result                    result
                     , y)
                    x
                 h(
              tc
            fe ult
              r es
 client
Normal Deferred
1     d = someFunc(arg1,arg2)

          cb1   cb2   cb3



2         d.addCallback()
    cb1   cb2   cb3   cb4   cb5


3         # Hope d fires!
Controllable Deferred
1   d = ControllableDeferred(someFunc,arg1,arg2)

             cb1     cb2    cb3



2             d.addCallback()
      cb1     cb2    cb3     ?      cb4    cb5


3   # If call to someFunc fires, call d.
    # Allow caller to call d.cancel
RetryingCall
Replace something like this
d = getPage(url)

With this
r = RetryingCall(getPage, url)
d = r.start()
Resizable Dispatch Queue
                 Tickery adder                  RDQ

                                               pending
WWW       put                         put   a b c d
                                              underway

Twitter                                         e
                     doWork                          f
FluidDB                              call        g


admin     pause, resume, stop, size,
          widen, narrow, underway, cancel

Weitere ähnliche Inhalte

Was ist angesagt?

Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache Hadoop
Sages
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
Moriyoshi Koizumi
 

Was ist angesagt? (20)

INFLUXQL & TICKSCRIPT
INFLUXQL & TICKSCRIPTINFLUXQL & TICKSCRIPT
INFLUXQL & TICKSCRIPT
 
Ntp cheat sheet
Ntp cheat sheetNtp cheat sheet
Ntp cheat sheet
 
MongoDB World 2019: Prepare Yourselves: Sharded Transactions Are Coming
MongoDB World 2019: Prepare Yourselves: Sharded Transactions Are ComingMongoDB World 2019: Prepare Yourselves: Sharded Transactions Are Coming
MongoDB World 2019: Prepare Yourselves: Sharded Transactions Are Coming
 
Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache Hadoop
 
Un dsl pour ma base de données
Un dsl pour ma base de donnéesUn dsl pour ma base de données
Un dsl pour ma base de données
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New Rope
 
R and C++
R and C++R and C++
R and C++
 
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob LisiUsing Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
 
Kapacitor Alert Topic handlers
Kapacitor Alert Topic handlersKapacitor Alert Topic handlers
Kapacitor Alert Topic handlers
 
Multi qubit entanglement
Multi qubit entanglementMulti qubit entanglement
Multi qubit entanglement
 
Oop lab report
Oop lab reportOop lab report
Oop lab report
 
Rcpp11
Rcpp11Rcpp11
Rcpp11
 
Performance testing of microservices in Action
Performance testing of microservices in ActionPerformance testing of microservices in Action
Performance testing of microservices in Action
 
Ns tutorial
Ns tutorialNs tutorial
Ns tutorial
 
Zone.js 2017
Zone.js 2017Zone.js 2017
Zone.js 2017
 
AnyEvent and Plack
AnyEvent and PlackAnyEvent and Plack
AnyEvent and Plack
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Performance Profiling in Rust
Performance Profiling in RustPerformance Profiling in Rust
Performance Profiling in Rust
 
The Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RI
The Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RIThe Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RI
The Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RI
 
Monitoring InfluxEnterprise
Monitoring InfluxEnterpriseMonitoring InfluxEnterprise
Monitoring InfluxEnterprise
 

Ähnlich wie Deferred Gratification

Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwr
deimos
 

Ähnlich wie Deferred Gratification (20)

JavaZone 2014 - Iteration 2.0: Stream
JavaZone 2014 - Iteration 2.0: StreamJavaZone 2014 - Iteration 2.0: Stream
JavaZone 2014 - Iteration 2.0: Stream
 
Clojure+ClojureScript Webapps
Clojure+ClojureScript WebappsClojure+ClojureScript Webapps
Clojure+ClojureScript Webapps
 
Design your client: go way
Design your client: go wayDesign your client: go way
Design your client: go way
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
 
Reactive x
Reactive xReactive x
Reactive x
 
HBase Client APIs (for webapps?)
HBase Client APIs (for webapps?)HBase Client APIs (for webapps?)
HBase Client APIs (for webapps?)
 
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
 
Message Queueing - by an MQ noob
Message Queueing - by an MQ noobMessage Queueing - by an MQ noob
Message Queueing - by an MQ noob
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
 
Openstack taskflow 簡介
Openstack taskflow 簡介Openstack taskflow 簡介
Openstack taskflow 簡介
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
Facebook C++网络库Wangle调研
Facebook C++网络库Wangle调研Facebook C++网络库Wangle调研
Facebook C++网络库Wangle调研
 
Message queueing
Message queueingMessage queueing
Message queueing
 
HBaseCon2017 Transactions in HBase
HBaseCon2017 Transactions in HBaseHBaseCon2017 Transactions in HBase
HBaseCon2017 Transactions in HBase
 
Java with a Clojure mindset
Java with a Clojure mindsetJava with a Clojure mindset
Java with a Clojure mindset
 
Writing Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaWriting Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & Akka
 
Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»
 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwr
 
FPV Streaming Server with ffmpeg
FPV Streaming Server with ffmpegFPV Streaming Server with ffmpeg
FPV Streaming Server with ffmpeg
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Deferred Gratification

  • 1. Deferred Gratification Patterns of asynchronous flow of control with Twisted deferreds Terry Jones terry@fluidinfo.com @terrycojones
  • 2. Not an intro talk. Sorry! • Assume you understand Deferreds • Assume you understand async
  • 3. Read defer.py • Lots of people don’t • Much of it is beautiful • Deferreds seem cryptic • They’re are actually very simple
  • 4. Building blocks Simple functions that help with deferreds • succeed • fail • maybeDeferred Classes that build on simple deferreds • DeferredList • DeferredQueue • DeferredSemaphore • DeferredLock
  • 5. Deferreds let you replace synchronous data structures with elegant asynchronous equivalents
  • 6. Some of our classes http://jon.es/other/europython-2010-deferreds.tar.bz2 • tee • RetryingCall • DeferredPooler } • ControllableDeferred • DeferredPool rdq.py • ResizableDispatchQueue
  • 7. DeferredPooler client client server whatever client
  • 8. DeferredPooler client fe tc h( x, y) client server whatever client
  • 9. DeferredPooler client fe tc h( x, y) fetch(x,y) client server whatever client
  • 10. DeferredPooler client fe tc h( x, y) fetch(x,y) fetch(x,y) client server whatever client
  • 11. DeferredPooler client fe tc h( x, y) fetch(x,y) fetch(x,y) client server whatever , y) ( x ch f et client
  • 12. DeferredPooler client fe tc h( x, y) fetch(x,y) fetch(x,y) client server whatever result , y) ( x ch f et client
  • 13. DeferredPooler client fe tc re h( su x, lt y) fetch(x,y) fetch(x,y) client server whatever result result , y) x h( tc fe ult r es client
  • 14. Normal Deferred 1 d = someFunc(arg1,arg2) cb1 cb2 cb3 2 d.addCallback() cb1 cb2 cb3 cb4 cb5 3 # Hope d fires!
  • 15. Controllable Deferred 1 d = ControllableDeferred(someFunc,arg1,arg2) cb1 cb2 cb3 2 d.addCallback() cb1 cb2 cb3 ? cb4 cb5 3 # If call to someFunc fires, call d. # Allow caller to call d.cancel
  • 16. RetryingCall Replace something like this d = getPage(url) With this r = RetryingCall(getPage, url) d = r.start()
  • 17. Resizable Dispatch Queue Tickery adder RDQ pending WWW put put a b c d underway Twitter e doWork f FluidDB call g admin pause, resume, stop, size, widen, narrow, underway, cancel

Hinweis der Redaktion