[Twisted-Python] Triggering callbacks on raw file descriptors

Brian Granger bgranger at scu.edu
Mon Jan 9 11:51:20 EST 2006

On Jan 8, 2006, at 9:41 PM, James Y Knight wrote:

> On Jan 8, 2006, at 1:46 AM, Brian Granger wrote:
>> When I killed the reactor, I got an exception:
>> exceptions.AttributeError: 'BonjourDescriptor' object has no  
>> attribute 'connectionLost'
>> It looks like the disconnectAll method on the reactor is calling  
>> reader.connectionLost on each reader.  Why is this so?
>> I thought I only needed to implement the IReadDescriptor interface  
>> for my reader, but the connectionLost method is not a part of that  
>> interface.  Hmmm.  Should I implement it?  What interface is that  
>> method in?  This seems confusing.
> connectionLost should have been on IFileDescriptor, the superclass  
> of IReadDescriptor. I just added it:
>>     def connectionLost(self, reason):
>>         """Called when the connection was lost.
>>         This is called when the connection on a selectable object  
>> has been
>>         lost.  It will be called whether the connection was closed  
>> explicitly,
>>         an exception occurred in an event handler, or the other  
>> end of the
>>         connection closed it first.
>>         See also L{IHalfCloseableDescriptor} if your descriptor  
>> wants to be
>>         notified separately of the two halves of the connection  
>> being closed.
>>         @param reason: A failure instance indicating the reason  
>> why the
>>          connection was lost.  L 
>> {twisted.internet.error.ConnectionLost} and
>>          L{twisted.internet.error.ConnectionDone} are of special  
>> note, but
>>          the failure may be of other classes as well.
>>         """
> Hope that helps.

> JP seems to disagree that it _should_ be part of the interface  
> (http://twistedmatrix.com/bugs/issue1408), but it _is_ currently  
> (and was previously, just undocumentedly so).

Adding connectionLost to the IFileDescriptor interface does solve the  
problem.  But the situation is more complicated than that - and that  
makes me a little hesitant to just have connectionLost in  
IFileDescriptor as you have done.  Here is why:

The IReactorFDSet interface, specifies that any class that implements  
the IReadDescriptor can be used as a reader.  But, currently, the  
reactor's, which supposedly IReactorFDSet implements also call the  
following on the readers:

logPrefix -- part of twisted.python.log.Logger which FileDescriptor  
(the class) inherits from
connectionLost -- now part of IFileDescriptor

Thus is looks like readers are actually required to also be a  
subclass of the Logger class (the FileDescriptor class, which is used  
for Port does this).  The problem seems to be with the IReactorFDSset  
interface which doesn't actually specify acccurately which interfaces  
(and subclasses) the  readers/writers must implement.  Is there a  
ILogger interface as well?

Also, this makes me worry that developers have been asusming that  
readers are actually a subclass of FileDescriptor.  Is that the case?

I am not that experienced with this part of twisted, so I am not sure  
what is the best solution.

Thanks for looking into this.


> James
> _______________________________________________
> 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