Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learning Twisted

Tags:

python

twisted

How do I begin learning Twisted? What books, documentation or tutorial do you guys recommend?

The reason I asked this question is that I think learning Twisted would help me otherwise also in learning concepts related to network programming (terminologies and how it works and stuff) I have heard that the documentation for Twisted is not that good. Is is true?

Note that I am looking for some advise that actually helped you. I am looking for your experience. PS: I am aware of the official documentation. There is also the O'Reilly Book on Twisted; is that good?

like image 946
user225312 Avatar asked Oct 02 '10 17:10

user225312


4 Answers

I'm finding this tutorial, linked to from the third party documentation section of the main twisted documentation page, to be well-written and instructive.

The tutorial consists of numerous iterations of the implementation of a "Poetry Server and Client". It starts with a blocking, non-Twisted version, and works up to a full Twisted version. Each step introduces new abstractions and presents problems which are resolved in the succeeding steps.

The code which implements each step is made available as a git repo.

like image 104
intuited Avatar answered Oct 22 '22 09:10

intuited


The way i learned twisted was by starting a small project and lots of googling around; the twisted tutorials are sometimes not very clear, its just getting used to the framework and the way it works... EDIT: itd also recommend trying to understand what twisted is based on, the whole idea of twisted is to provide event driven programming for python, along with some other features such as asynchronous sockets and web server classes.

A quick explanation of deferreds and callbacks, which is the whole idea behind twisted, is creating an event (deferred object), then attaching a callback to it; then at some point ur going to fire the event, and the callback is triggered with a result (it could be null) from ur event operation. A good example is, if you have a button on a form, you create an event (a deferred object) then u attach a callback, when the user clicks a button, they fire the event, and the callback function is called to handle that event.

i hope this will give u a good general idea of what twisted is and how it can be used in a python environment, there is also IronPython (.NET) which has eventing as well.

~george

like image 39
mayotic Avatar answered Oct 22 '22 08:10

mayotic


Look at the samples that come with twisted's documentation. Also, the documentation is not bad, but it is not very complete. Also, the API docs are quite good in fact.

When you know with which part you start, just try and play with the code until you're stuck, then google samples relating to your code and ask on stackoverflow.

like image 2
knitti Avatar answered Oct 22 '22 07:10

knitti


As mentioned before the Krondo Twisted Introduction is pretty nice. But the Twisted book by o'reilly isn't bad either. I've only got the first edition (from 2005) of the book and I think it is better structured than the Krondo tutorial.

It includes standard tasks (like downloading a web page) and gives two sections to every task.

"How do I do that" and afterwards "How does it work".

I think the book is pretty good if you don't have the time (or don't want to take it) to read through the Krondo tutorial.

One thing I miss in the o'rilley book though is inline callbacks. Maybe they've added some chapter about it in new editions, since inline callbacks were added later to twisted.

Especially if you are not a fan of reading from a screen I would suggest getting the book. (Also it includes an interresting foreword from the twisted inventor)

like image 1
phi-j Avatar answered Oct 22 '22 08:10

phi-j