[Twisted-Python] perspective argument missing from Viewable.view_*

Daniel Sank sank.daniel at gmail.com
Sun Nov 17 18:20:24 MST 2013


I'm trying to understand exactly how context management works in
perspective broker. I thought the point of Viewable was that you
always know who's calling. However if I run the simple fully working
example pasted below, I see that the perspective argument is None.
What gives?

Kind regards,
Daniel Sank

# Server

import twisted.spread.pb as pb
import twisted.internet.reactor as reactor

class Server(pb.Root):
    def __init__(self):
        self.v = MyViewable()

    def remote_getViewable(self):
        return self.v

class MyViewable(pb.Viewable):
    def view_foo(self, perspective):
        print ("Perspective %s"%perspective)


if __name__ == "__main__":
    reactor.listenTCP(54321, pb.PBServerFactory(Server()))
    print("Starting reactor")
    reactor.run()

# Client

import twisted.spread.pb as pb
import twisted.internet.reactor as reactor
from twisted.internet.defer import inlineCallbacks

@inlineCallbacks
def gotRoot(root):
    v1 = yield root.callRemote("getViewable")
    v2 = yield root.callRemote("getViewable")
    print(v1)
    print(v2)
    yield v1.callRemote("foo")
    yield v2.callRemote("foo")

factory = pb.PBClientFactory()
reactor.connectTCP("localhost", 54321, factory)
d = factory.getRootObject()
d.addCallback(gotRoot)
reactor.run()



More information about the Twisted-Python mailing list