[Twisted-Python] How to invoke the remote method based on twisted in django web app?

Boern cayson.z at gmail.com
Fri Mar 6 21:45:03 MST 2009


thanks,all. I have resolved it by twisted.web .xmprpc

On Fri, Mar 6, 2009 at 7:44 PM, Burus <eburus at gmail.com> wrote:

> You can try starting reactor. in the settings.py file, and use twisted  pb
> calls in the fjango views.
>
>
> On Fri, Mar 6, 2009 at 2:33 PM, Phil Mayers <p.mayers at imperial.ac.uk>wrote:
>
>> 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 at twistedmatrix.com
>> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>>
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>


-- 
Boern Parx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20090307/39516dd7/attachment.html>


More information about the Twisted-Python mailing list