[Twisted-Python] Perspective broker over standard IO. How?
Maxim Lacrima
lacrima.maxim at gmail.com
Fri Feb 8 07:01:53 EST 2013
Hi!
I can't figure out how to use Perspective broker over stdio. Say I have
file `child.py`:
----
from twisted.internet.endpoints import StandardIOEndpoint
from twisted.internet import reactor
from twisted.spread import pb
class Foo(pb.Root):
def remote_do_smth(self):
pass
def main():
endpoint = StandardIOEndpoint(reactor)
f = pb.PBServerFactory(Foo())
endpoint.listen(f)
reactor.run()
if __name__ == '__main__':
main()
----
Then say I have `main.py`:
----
import sys
from twisted.spread import pb
from twisted.internet import reactor
def cb(o):
d = o.callRemote("do_smth")
return d
def main():
exe = sys.executable
args = [exe, '/path/to/child.py']
factory = pb.PBClientFactory()
# now what? The below is a wrong way to create protocol.
# But how do I do this?
proto = factory.buildProtocol(('foo',))
reactor.spawnProcess(proto, exe, args)
d = factory.getRootObject()
d.addCallback(cb)
d.addCallback(lambda _: reactor.stop())
reactor.run()
if __name__ == '__main__':
main()
----
How do I spawn `child.py` from a parent process, such that the parent can
retrieve the root object and call methods on it?
The code above throws errors:
http://pastebin.com/7TiZdDVc
Thanks in advance.
--
Regards,
Maxim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20130208/a30693b6/attachment.htm
More information about the Twisted-Python
mailing list