[Twisted-Python] How to make a service dependent of another?

Jean-Paul Calderone exarkun at divmod.com
Fri May 15 08:38:01 MDT 2009


On Fri, 15 May 2009 11:11:58 +0300, coder_gus <coder_gus at lavabit.com> wrote:
>Hi,
>I have a pb client and a tcp server. How can I make the server start
>only after/if the client started?

In general, the answer to "how do I do X when Y?" is "Put the code to do X
in the callback that tells you Y has happened."

So, for example, if you're using PBClientFactory.login, you might add a
callback to the Deferred it returns which starts your TCP server.  ie,


    f = PBClientFactory(...)
    d = f.login(...)
    def cbLoggedIn(avatar):
        reactor.listenTCP(...)
        ...
    d.addCallback(cbLoggedIn)
    ...
    reactor.connectTCP(..., f)
    reactor.run()

Jean-Paul




More information about the Twisted-Python mailing list