You can try starting reactor. in the settings.py file, and use twisted pb calls in the fjango views.<br><br><div class="gmail_quote">On Fri, Mar 6, 2009 at 2:33 PM, Phil Mayers <span dir="ltr"><<a href="mailto:p.mayers@imperial.ac.uk">p.mayers@imperial.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">Boern wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
hi,all:<br>
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.<br>
example:<br>
<br>
the remote service code :<br>
<br>
class Echoer(pb.Root):<br>
def remote_echo(self, task):<br>
print 'echoing:', task<br>
return task<br>
<br>
if __name__ == '__main__':<br>
reactor.listenTCP(8789, pb.PBServerFactory(Echoer()))<br>
reactor.run()<br>
<br>
-------------------------------------------------------------------------------------------------------------<br>
and the djiango views.py code :<br>
<br>
def register_task(requst):<br>
"""register the task"""<br>
.................<br>
factory = pb.PBClientFactory()<br>
reactor.connectTCP("localhost", 8789, factory)<br>
d = factory.getRootObject()<br>
d.addCallback(lambda object: object.callRemote("echo", task))<br>
d.addCallback(lambda echo: 'server echoed: '+echo[0]+str(echo[1]))<br>
d.addErrback(lambda reason: 'error: '+str(reason.value))<br>
d.addCallback(util.println)<br>
d.addCallback(lambda _: reactor.stop())<br>
reactor.run()<br>
</blockquote>
<br></div>
That won't work. The reactor cannot be started more than once. It needs to be long-lived.<br>
<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</blockquote></div><br>