writing network applications in Python • Best known for “Deferreds”, Twisted’s async abstraction • Contains protocol implementations for HTTP, SMTP, IMAP, DNS, etc.
event loop, or “reactor”. • This is an infinite loop, wrapped around a blocking call that waits until some I/O is ready • Once the I/O is ready, this fires off an event to run the code that was waiting for it • Runs other tasks while I/O blocked tasks are waiting
Deferreds, which are an IOU for a result • A Deferred contains a callback chain, a series of functions run in sequence after it gets a result • Deferreds get their results from events occurring, such as I/O
the result of the previous one as its first argument • Functions in the callback chain can return either a result or a Deferred that fires with a result sometime in the future
into sections, broken up over external interface accesses • Encourages reuse, as these sections quite commonly do one thing to an input and return it • Can be cancelled (eg. if a client disconnected and you don’t care about the result anymore)
execution threads share the same global state • No global mutable state means you can scale easier • If your global state is databases, just spin up more Twisted instances to use all your CPUs
POP3 and IMAP4 servers and clients • Support for TLS-secured email out of the box For more info, see: http://twistedmatrix.com/documents/ current/mail/index.html
box twistd -n dns -c —port 10053 --recursive • DNS client APIs • DNS server toolkit For more info, see: http://twistedmatrix.com/documents/ current/names/howto/custom-server.html