[Twisted-Python] Socket Read Write

Andrew Bennetts andrew-twisted at puzzling.org
Mon Nov 3 05:24:27 MST 2003


On Mon, Nov 03, 2003 at 07:03:48AM -0500, Ted Patrick wrote:
> I am writing a chat socket server and need to make sure that there are no
> conflicts when writing to other attached clients. I am concerned that when
> the server receives lots of messages from many socket connections, several
> sockets may encounter write contention. 

Twisted's network code is single-threaded.  Only one event is processed at
once, so the answers to your questions are:

> Is there a queue for the write method of a socket? 

No -- there doesn't need to be.  The transport will buffer any write that
isn't immediately writeable without blocking, but because you never do this
from more than one thread at a time, there are no possible races here.

> Should one expect errors in this regard?

Nope :)

> Does the Twisted architecture eliminate this class of error?

Yep :)

> Using twisted.protocol.basic can 2 lineReceived events happen
> simultaneously? How is this addressed?

They can't happen simultaneously. :)

If you are using threads in your Twisted app, be sure to read:
    http://twistedmatrix.com/documents/howto/threading

-Andrew.





More information about the Twisted-Python mailing list