[Twisted-Python] From asyncore to twisted

glyph at divmod.com glyph at divmod.com
Fri May 2 12:32:07 EDT 2008

On 1 May, 10:09 pm, daniel.brandt at gmail.com wrote:
>I'm looking for some advice on how to get started with an asyncore ->
>Twisted conversion. Being new to  twisted I have some trouble getting
>started (re)designing my system. All ideas are welcome since I'm also
>doing this to learn.

I suggest that you do these things one at a time.

While I am practically overflowing with advice about how to architect 
Twisted applications, I don't think it would be appropriate to give it 
all to you right now.

Get your application running on Twisted under more or less the same 
architecture, and then once you've ported over the basics - protocols 
and transports, timed events - you should notice that you can delete 
some of the things in your asyncore application that were doing things 
that Twisted is now doing for you.

Once you've got a fully working Twisted app (with, of course, full unit 
test coverage) that's the time to start looking at how to best improve 
it.  Trying to simultaneously convert to Twisted and improve your design 
will lead to things breaking, leaving you thinking "this used to work 
*before*..." and scratching your head, wondering if it's the new design 
that's buggy or it's some detail of Twisted you don't understand.
>I'm a bit confused about what parts should be in the Protocol and what
>should be separated away from it. Should I make a specialized Factory
>or make a Service (or several depending on what type of client
>connection it is)?

A Protocol represents an individual connection between a client and 
server; a factory roughly represents a listening (or connecting) port 
where incoming connections may be initiated; when connections are 
started via a Factory, Protocols are created.

Keep the things on the Protocol that were on your asyncore "channels", 
and use factories for objects that previously had a "handle_connect" 

I wouldn't worry at all about Services just yet; the only place you need 
to care about them is your start-up and shut-down code.

More information about the Twisted-Python mailing list