Concurrency
We got “Both Kinds”
- I/O Bound - Twisted's Domain
- Compute Bound - Twisted Can Help
- Non-Blocking Calls
- Register Callback - O.registerCallback(fn, *args, **kargs)
“fn” can be function or method
def fn(result, *args, **kargs) ← signature of callback
- Use Deferreds
d = O.meth(...)
- d.addCallback(fn,*args,**kargs)
- d.addCallback(fn2, ...)
- d.addErrback(errfn,...)
- Register Callback - O.registerCallback(fn, *args, **kargs)
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
...