The code below is taken from Twisted's documentation on AMP (link). When a callback is added to d, there's automatically a "protocol" argument added to it and the deferred is automatically run when reactor.run() is called.
def connect():
endpoint = TCP4ClientEndpoint(reactor, "127.0.0.1", 8750)
factory = Factory()
factory.protocol = AMP
return endpoint.connect(factory)
d = connect()
def connected(protocol):
return protocol.callRemote(
RegisterUser,
username=u'alice'
d.addCallback(connected)
reactor.run()
In my code, everything is exactly the same, except I've been using pyglet-twisted (link) with cocos2d so I can't call reactor.run() because the reactor starts at the same time as the application.
If I call reactor.run(), I get an error saying the reactor is already running.
If I don't, the deferred doesn't seem to get called.
I've been trying to call it with reactor.callLater, reactor.callWhenRunning, but both need an argument. Passing in None doesn't work.
So my question is, how should I make this this deferred run without calling reactor.run().
Thanks!