[Twisted-Python] newbie question: error handling

Glyph Lefkowitz glyph at twistedmatrix.com
Mon Dec 31 08:08:52 MST 2001


On Sun, 2001-12-30 at 17:44, Ivo van der Wijk wrote:
> Hi All,
> 
> I'm currently migrating my irc client to twisted, and things look
> promising.
> 
> However, I can't figure out the following things:
> 
> My protocol is derived from protocols.basic.LineReceiver
> (which in turn derives from protocol.Protocol.protocol).
> 
> How can I determine what specific error condition caused connectionLost()
> or connectionFailed()? I.e. connection refused, unknown hostname,
> no route to host, etc (the standard errno stuff). 

Currently you can't.  This is the first request I'm aware of to be made
aware of the actual errno that caused the connection to fail; the
distinction between connectionFailed and connectionLost seemed to be the
big one.

The place you'd have to fix would be
twisted.internet.tcp.Connection.(doRead|writeSomeData).  Similarly in
twisted.internet.udp.  Patches accepted :-).

> Also, how can I determine if Linereceived.sendLine() (or 
> Protocol.Transport.write()) failed? It doesn't seem to return an
> error value or raise Exceptions, and depending on the invocation
> of connectionLost makes things perhaps too asynchronous..

If you need this level of guarantee, you need a protocol which will send
acks for messages as they've been received.  There is no such thing as
"too asynchronous" -- there is "synchronous", "asynchronous", and
"sometimes stuck doing something with one client while the rest of the
server hangs..." :-).

This is the same question as previously, really; if a write "fails",
then the connection has been lost.  Knowing that a connection failed
during a write and getting an errno would give you all the same
information.

Keep in mind that a write "succeeding" might just mean that the memory
was succesfully copied into a buffer for your OS kernel to send; the
other side of the connection may never have received it.

-- 
______      you are in a maze of twisted little applications, all
|   |_\     remarkably consistent.
|     |          -- glyph lefkowitz, glyph @ twisted matrix . com
|_____|             http://www.twistedmatrix.com/





More information about the Twisted-Python mailing list