Boern wrote:
hi,all:
I developed a web app in diango and a remote service in twisted, and I
want to invoke the twisted remote method in django web.
example:
the remote service code :
class Echoer(pb.Root):
def remote_echo(self, task):
print 'echoing:', task
return task
if __name__ == '__main__':
reactor.listenTCP(8789, pb.PBServerFactory(Echoer()))
reactor.run()
-------------------------------------------------------------------------------------------------------------
and the djiango views.py code :
def register_task(requst):
"""register the task"""
.................
factory = pb.PBClientFactory()
reactor.connectTCP("localhost", 8789, factory)
d = factory.getRootObject()
d.addCallback(lambda object: object.callRemote("echo", task))
d.addCallback(lambda echo: 'server echoed: '+echo[0]+str(echo[1]))
d.addErrback(lambda reason: 'error: '+str(reason.value))
d.addCallback(util.println)
d.addCallback(lambda _: reactor.stop())
reactor.run()
That won't work. The reactor cannot be started more than once. It needs
to be long-lived.
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python