ReconnectingClientFactory.stopTrying
does work. Any time you have a question like this, you shouldn't just say "doesn't work". You should explain your expectations, give a minimal example of the code you're trying, and explain how its behavior differs from your expectations.
For this case, here's an example which demonstrates how stopTrying
meets my expectations, which are that after it is called, no further attempts will be made to establish the connection:
from twisted.internet.protocol import ReconnectingClientFactory
from twisted.internet import reactor
from twisted.python.log import startLogging
from sys import stdout
def main():
startLogging(stdout)
f = ReconnectingClientFactory()
reactor.callLater(10, f.stopTrying)
reactor.connectTCP('localhost', 12345, f)
reactor.run()
if __name__ == '__main__':
main()
This will run forever, but for the first 10 seconds of its run, it will be making new connection attempts (which all fail). After stopTrying
is called, it will stop making such attempts.