Differences between revisions 1 and 2
Revision 1 as of 2008-05-07 19:56:23
Size: 1062
Editor: GlennTarbox
Comment:
Revision 2 as of 2008-05-07 22:53:47
Size: 1474
Editor: GlennTarbox
Comment:
Deletions are marked like this. Additions are marked like this.
Line 10: Line 10:
 * We got “Both Kinds”
  * I/O Bound - Twisted's Domain
  * Compute Bound - Twisted Can Help
== We got Both Kinds ==
Line 14: Line 12:
 * Non-Blocking Calls
  * Register Callback - O.registerCallback(fn, *args, **kargs)
   * “fn” can be function or method
   * def fn(result, *args, **kargs) ← signature of callback
 * I/O Bound
 * Compute Bound

== Waiting For Answers ==
 1. Just Wait... wasn't doing nothin' anyway
 1. Spawn Process
 1. Spawn Thread
 1. Non-blocking calls and "a plan"

== Non-Blocking Calls ==
  * Register Callback
{{{#!python
O.registerCallback(fn, *args, **kargs) # fn can be function or method

def fn(result, *args, **kargs)
  print "important message: ", result
}}}
Line 19: Line 31:
   * d `=` O.meth(...)
   * d.addCallback(fn,*args,**kargs)
   * d.addCallback(fn2, ...)
   * d.addErrback(errfn,...)
{{{#!python
d = O.doComplicatedLengthyCalc(a,b,c) # returns deferred
def gotResult(result)
  print "important message: ", result
  return "a more important message"
d.addCallback(gotResult) # first callback
def gotResult2(result)
   print "gotResult2 returns: ", result # will print "a more important message"
d.addCallback(fn2, ...)
d.addErrback(errfn,...) # exception handling for deferreds
}}}

Navigation(slides)

Concurrency

We got Both Kinds

  • I/O Bound
  • Compute Bound

Waiting For Answers

  1. Just Wait... wasn't doing nothin' anyway
  2. Spawn Process
  3. Spawn Thread
  4. Non-blocking calls and "a plan"

Non-Blocking Calls

  • Register Callback

   1 O.registerCallback(fn, *args, **kargs) # fn can be function or method
   2 
   3 def fn(result, *args, **kargs)
   4   print "important message: ", result
  • Use Deferreds

   1 d = O.doComplicatedLengthyCalc(a,b,c) # returns deferred
   2 def gotResult(result)
   3   print "important message: ", result
   4   return "a more important message"
   5 d.addCallback(gotResult)             # first callback
   6 def gotResult2(result)
   7    print "gotResult2 returns: ", result # will print "a more important message"
   8 d.addCallback(fn2, ...)
   9 d.addErrback(errfn,...)    # exception handling for deferreds

If you need to call a method that returns a deferred within your callback chain, just return that deferred, and the result of the secondary deferred's processing chain will become the result that gets passed to the next callback of the primary deferreds processing chain

...

Navigation(siblings)

DsageNg/TwistedTalk/100_Twisted_Deconstructed (last edited 2008-11-14 13:41:51 by localhost)