[Twisted-Python] Migrate Asyncore to Twisted

Sean Roark srock258 at gmail.com
Wed Mar 14 11:32:09 EDT 2007


>Assuming that your python program is connected to your two
>devices with two independent TCP connections, your python
>program actually is doing message based routing among two
>async bi-directional tcp channels.

This is a very good way to describe it, thank you.

>Four extra threads is four more than there's any reason to have here.  Two
>threads per socket is the kind of thing Twisted exists to let you avoid.

Even with asyncore I don't need two threads per connection. The asyncore
loop handles the send and receive just fine. My Queue interface between my
application and the comms layer is what I need a protocol for. Abstractly,
it isn't complicated, I just don't have time to go down that road without
any guidance because if it takes more then a day or two I'm toast.

I'm more interested in a mapping from asyncore dispatcher to twisted
protocol. This is on my to do list to figure out but for my current project
i don't have time. Something filling in these blanks would be perfect:

Asyncore.dispatcher ----->Twisted Protocol
handle_connect ------------> ?
handle_read      ------------> read, getline, readraw, etc...
handle_write     ------------> sendline, send, etc...
handle_expt     ------------> ?
?                    -------------> buildFactory
asyncore.loop  ------------> reactor.run

Obviously need more then just that.

I have found the online examples and documentation to be quite terse when
describing how things fit together. When I eventually get the chance to make
this migration I plan to write a tutorial. In my opinion the less legacy
code directly using asyncore in this world, the better, so may as well make
it easy to migrate.

Sean

On 3/14/07, Jean-Paul Calderone <exarkun at divmod.com> wrote:
>
> On Wed, 14 Mar 2007 00:26:23 -0700, jian wu <hellojianwu at gmail.com> wrote:
> >Hi Sean,
> >>I am actually not sure if it is my protocol that is complicated
> >>or if the way in which I want to pass the data that is complicated.
> >
> >I should claim that I'm not very well experienced with either Twisted
> >or asyncore, My guess is that is not protocol but the way to pass
> >data.
> >
> >Assuming that your python program is connected to your two
> >devices with two independent TCP connections, your python
> >program actually is doing message based routing among two
> >async bi-directional tcp channels.
> >
> >My guess is that you can keep two Queues since it will help
> >keeping the order of the async messages received and processed.
> >And, since twisted has a thread pool, it might be doable that
> >you could create four threads, two for each TCP Connections,
> >one thread for read and another for write per TCP connection,
> >the read thread will handle the received message, process it
> >and put it into the Queue, the write thread will take the message
> >from the Queue and write it out to the targeted TCP connection.
> >
>
> Four extra threads is four more than there's any reason to have here.  Two
> threads per socket is the kind of thing Twisted exists to let you avoid.
>
> Jean-Paul
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>



-- 

Sean Roark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20070314/2977ed12/attachment.htm 


More information about the Twisted-Python mailing list