[Twisted-Python] CONNECTION_LOST not an integer (docstring error?)

Michael McNeil Forbes mforbes at physics.ubc.ca
Wed Oct 1 15:24:05 MDT 2008


On Oct 1, 2008, at 12:04 PM, Jean-Paul Calderone wrote:

> On Wed, 1 Oct 2008 12:00:29 -0600, Michael McNeil Forbes  
> <mforbes at physics.ubc.ca> wrote:
>> Several places in the documentation refer to the method  
>> writeSomeData () returning a negative integer if the connection is  
>> lost.  (In  particular /api/  
>> twisted.internet.abstract.FileDescriptor.html#writeSomeData.)
>>
>> However, twisted.internet.main.CONNECTION_LOST is often returned   
>> which is not an integer.
...
> Hardly anyone actually needs `writeSomeData`.  It's mostly an  
> implementation
> detail of a certain group of reactors.

I have opened a ticket.  A question then that is sure to expose my  
ignorance of twisted...

Why does writeSomeData not simply raise CONNECTION_LOST as an  
exception?  Checking return values is quite un-pythonic.  Is there a  
deep reason for this?

Michael.

P.S. I came across this because I was trying to use twisted running  
in a thread to write data resulting from a long computation that I  
have not yet turned into a producer.  The more conventional "write"  
method was failing if the socket backed up, and provided no simple  
way of determining if data was being dropped.  My solution was to  
used writeSomeData, and then have the computation decide to throw out  
some of the data if it is being produced too rapidly, but I need to  
know how much has been sent so I can decide what to throw away...





More information about the Twisted-Python mailing list