[Twisted-Python] Migrate Asyncore to Twisted

jian wu hellojianwu at gmail.com
Thu Mar 15 00:38:20 MDT 2007


Hi Sean,

> Even with asyncore I don't need two threads per connection. The
> asyncore loop handles the send and receive just fine.

I think that I had better correcting my term as "4 types of threads" or
"4 types of threading tasks" since Twisted has a thread pool, so you
don't need start thread by your python code, you just submit your
task to Twisted Thread Pool, it'll schedule and run for you.

> 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.

Again, I might not be the right person to define the mapping.
Also, I think that you don't have to restrict yourself in an
one-to-one-map-porting mode since Twisted has more rich
features and functionalities than "asyncore", such as thread
pool and that should be other alternative way to implement
async message routing like using Deferred along with Callback
Chain.

This is just my 2 cents.

Best regards,

Jian


On 3/14/07, Sean Roark <srock258 at gmail.com> wrote:
> >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
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>




More information about the Twisted-Python mailing list