[Twisted-Python] Explicitly closing an AMP connection?

Jean-Paul Calderone exarkun at divmod.com
Wed Apr 16 11:40:13 MDT 2008


On Wed, 16 Apr 2008 11:23:32 -0600, Nathan <nathan.stocks at gmail.com> wrote:
>What's the "twisted" way of cleanly closing an AMP connection?  The
>closest thing I can find on
>
>http://twistedmatrix.com/documents/current/api/twisted.protocols.amp.AMP.html
>
>is stopProducing() -- but it's undocumented.  Will that kill the connection?
>

Since AMP is an IProtocol implementation, it is given a reference to its
transport via the makeConnection method (commonly inherited from Protocol
and not overridden - the base implementation sets it as an attribute of
itself, `transport´).  The way to close a TCP connection is to call the
transport's loseConnection method.  So if you have a reference to a
connected AMP instance and you want to disconnect it, you can do

    theProto.transport.loseConnection()

Jean-Paul




More information about the Twisted-Python mailing list