[Twisted-Python] how to drop connection

Brian Warner warner at lothar.com
Wed Jul 30 00:33:37 MDT 2003


"Michael Porter" <mporter at despammed.com> writes:
> 
> I'm trying to close down a web server (wihout closing the application) but
> am having problems closing already established connections.

Maybe something like this? (note: completely untested):

class DroppingHTTPChannel(http.HTTPChannel):

    def connectionMade(self):
        http.HTTPChannel.connectionMade(self)
        self.factory.currentConnections.append(self)

    def connectionLost(self, reason):
        http.HTTPChannel.connectionLost(self, reason)
        self.factory.currentConnections.remove(self)

class DroppingHTTPFactory(http.HTTPFactory):

    currentConnections = []
    protocol = DroppingHTTPChannel

    def stopFactory(self):
        http.HTTPFactory.stopFactory(self)
        for p in self.currentConnections:
            p.transport.loseConnection()

hope that seems useful..
 -Brian




More information about the Twisted-Python mailing list