[Twisted-Python] Migrate Asyncore to Twisted

Jean-Paul Calderone exarkun at divmod.com
Wed Mar 14 09:14:03 EDT 2007

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


More information about the Twisted-Python mailing list