Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Though I have no real experience with rpyc, from your example it seems the only real difference is when executing the returnObject function the 'conn' reference is not retained, so I am guessing the situation has to do with garbage collection of whatever is referenced by 'conn'. With a slight modification to the returnObject function so that 'conn' is returned and retained outside the function, the example seems to execute.</p> <pre><code>&gt;&gt;&gt; import rpyc &gt;&gt;&gt; def returnObject(objName, host, port): ... conn = rpyc.connect(host, port) ... print conn ... attr = getattr(conn.root, 'get_' + objName)() ... print attr ... return conn, attr ... &gt;&gt;&gt; conn, share = returnObject('shared', 'localhost', 18861) &lt;rpyc.core.protocol.Connection 'conn1' object at 0x10b0676d0&gt; &lt;__main__.SharedClass object at 0x1091ff790&gt; &gt;&gt;&gt; share &lt;__main__.SharedClass object at 0x1091ff790&gt; &gt;&gt;&gt; share.action() </code></pre> <p>As I am involved in development of another python remote-object solution <a href="https://versile.com/products/vpy/" rel="nofollow">Versile Python</a>, just for fun here is an alternative implementation using that solution (requires VPy dev release 0.7.2, next version will have some conflicting API changes). Remote service providing SharedClass access:</p> <pre><code>from versile.quick import * from versile.vse.native.python import VPythonObject VSEResolver.add_imports() class SharedClass(object): def action(self): return u'I am doing something' shared = SharedClass() class Gateway(VExternal): @publish(show=True, ctx=False) def get_shared(self): return VPythonObject(shared) service = VTPService(lambda: Gateway(), auth=None) service.start() </code></pre> <p>Client code to access the service:</p> <pre><code>&gt;&gt;&gt; from versile.quick import * &gt;&gt;&gt; VSEResolver.add_imports() &gt;&gt;&gt; gw = VUrl.resolve('vtp://localhost/') &gt;&gt;&gt; shared = gw.get_shared() &gt;&gt;&gt; shared._v_activate() # required for activating as remote-python proxy &gt;&gt;&gt; shared.action() u'I am doing something' &gt;&gt;&gt; gw._v_link.shutdown() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload