<div dir="ltr">Hi!<div><br></div><div>I can't figure out how to use Perspective broker over stdio. Say I have file `child.py`:</div><div><br></div><div>----</div><div><div>from twisted.internet.endpoints import StandardIOEndpoint</div>
<div>from twisted.internet import reactor</div><div>from twisted.spread import pb<br></div></div><div><br></div><div><div>class Foo(pb.Root):</div><div> def remote_do_smth(self):</div><div> pass</div><div><br></div>
<div>def main():</div><div> endpoint = StandardIOEndpoint(reactor)</div><div> f = pb.PBServerFactory(Foo())</div><div> endpoint.listen(f)</div><div> reactor.run()</div><div><br></div><div>if __name__ == '__main__':</div>
<div> main()</div></div><div>----</div><div><br></div><div style>Then say I have `main.py`:</div><div style>----</div><div style><div>import sys</div><div>from twisted.spread import pb</div><div>from twisted.internet import reactor</div>
<div><br></div><div>def cb(o):</div><div> d = o.callRemote("do_smth")</div><div> return d</div><div><br></div><div>def main():<br></div><div> exe = sys.executable</div><div> args = [exe, '/path/to/child.py']</div>
<div><br></div><div> factory = pb.PBClientFactory()</div><div> # now what? The below is a wrong way to create protocol. </div><div> # But how do I do this?</div><div style> proto = factory.buildProtocol(('foo',))</div>
<div> reactor.spawnProcess(proto, exe, args)</div><div><br></div><div><div> d = factory.getRootObject()</div><div> d.addCallback(cb)</div><div> d.addCallback(lambda _: reactor.stop())</div></div><div><br></div>
<div> reactor.run()</div><div> </div><div>if __name__ == '__main__':</div><div> main()</div><div>----</div></div><div><br></div><div>How do I spawn `child.py` from a parent process, such that the parent can retrieve the root object and call methods on it?</div>
<div><br></div><div>The code above throws errors:</div><div><br></div><div><a href="http://pastebin.com/7TiZdDVc">http://pastebin.com/7TiZdDVc</a></div><div><br></div><div>Thanks in advance.<br clear="all"><div><br></div>
-- <br>
<div dir="ltr">Regards,<br>Maxim</div>
</div></div>