The twisted Framework

Presenter

Justin Warren

The twisted Framework

Asynchronous, Event Based

Protocol/Factory Style

Lots of pre-built protocol modules

Can link in to threaded model

deferToThread()

Asynchronous vs Threaded

Threaded simpler for novice

Each thread has the same code

Threads block on I/O

Inter-thread communication and locking required

Difficult to debug

Annoying to terminate

Asynchronous more complex for novice

State maintenance required

Blocking on I/O avoided

Inter-process communication simpler

Easier to debug

Easier to make faster

Threading Example

Asynchronous Example

rawDataReceived Example

Deferreds
The best thing since sliced bread

A Deferred is an encapsulated callback

Callback

Errback

Anything that might block can be wrapped in a Deferred object.

deferToThread()

Deferreds can be linked.

Asynchronous Principles

Code for events

Never block, Defer

Do it quickly, then return

callLater Example

Fin

2005-07-11T20:02:50