[Twisted-Python] ConnectionMixin.loseConnection (in _newtls) lacking arguments

Glyph glyph at twistedmatrix.com
Thu Dec 29 18:19:42 EST 2011


On Dec 27, 2011, at 7:01 AM, Saúl Ibarra Corretgé wrote:

> Hi all,
> 
> I'm experiencing a TypeError exception in my code since I updated to
> Twisted 11.1. After hunting it it seems to be caused because the
> loseConnection function from (_newtls) lacks arguments.
> 
> If there is no OpenSSL support present in the system the
> loseConnection function will be called in abstract.FileDescriptor
> (please, correct me if I'm wrong), and the signature for
> loseConnection is the following:
> 
> def loseConnection(self, _connDone=failure.Failure(main.CONNECTION_DONE)):
> 
> Shouldn't it be the same for _newtls.ConnectionMixin ? Or perhaps it
> should accept *args and **kw and pass them on? Or am I wrong here?
> 
> 
> Thanks and regards,
> 
> -- 
> /Saúl
> http://saghul.net | http://sipdoc.net

Hi Saúl,

The _connDone argument there is an internal convenience for that implementation of loseConnection(); it is not part of the API.  ITransport specifies that loseConnection takes no arguments.  See here: <http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.ITransport.html#loseConnection>.  You should fix your code to never pass an argument to loseConnection, as other transport implementations may also lack this argument.  (As a bizarre accident, the IOCP reactor also has this argument in its transport implementation, but there's no reason that it necessarily should.)

However, the fact that you thought otherwise is a bug in our documentation :).  Please feel free to file tickets (<http://twistedmatrix.com/trac/newticket>) describing how you got to the loseConnection that takes an argument and why you didn't realize that you should be looking at ITransport instead :).

Thanks,

-glyph




More information about the Twisted-Python mailing list