Phil
Phil

Reputation: 103

Removing clients from the reactor in Twisted

I have a simple TCP client which is connected to twisted using:

reactor.connectTCP(host, port, SomeClientFactory())

The program is able to receive a HUP signal to trigger a reload. I'd like to basically:

  1. Remove the old clients
  2. Reload config
  3. Create new clients based upon new config

However, I can't seem to find a way to acheive the first of these points. Any tips?

Thanks

Upvotes: 1

Views: 1878

Answers (1)

Jean-Paul Calderone
Jean-Paul Calderone

Reputation: 48325

IReactorTCP.connectTCP returns an IConnector provider. As you can see on the definition of the IConnector interface, the disconnect method will do something like what you want. You can also use the protocol instance's transport attribute's loseConnection method, of course. The latter would be more suitable if there's any kind of cleanup you want the protocol to do before actually disconnecting, since you could put that work and a call to loseConnection at the end of a method like shutdown or quit or cleanup on the protocol class and then just call that.

Upvotes: 2

Related Questions