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

Burus eburus at gmail.com
Fri Mar 6 06:44:15 EST 2009


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090306/c1c47d9d/attachment.htm 


More information about the Twisted-Python mailing list