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 l开发者_运维知识库ike to basically:
- Remove the old clients
- Reload config
- 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
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.
精彩评论