Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning remote object in rpyc
    primarykey
    data
    text
    <p>I have a remote server like below which already has an initialized class and i have set protocol config as allow public attrs True.</p> <pre><code>import rpyc class SharedClass(object): def __init__(self,string): print string def action(self): print 'i am doing something' s=SharedClass('hi') class MyService(rpyc.Service): def on_connect(self): pass def on_disconnect(self): pass def exposed_get_shared(self): return s if __name__=='__main__: from rpyc.utils.server import ThreadedServer t=ThreadedServer(MyService,port=18861,protocol_config={"allow_public_attrs":True}) t.start() </code></pre> <p>At the client side if i try to connect directly it is working, whereas when i try to make connection inside a function and return the object i am getting an error</p> <p>**Client**</p> <p>**Direct connection**</p> <pre><code>&gt;&gt;&gt;Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 &gt;&gt;&gt;Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt;conn=rpyc.connect('localhost',18861) &gt;&gt;&gt;share=getattr(conn.root,'get_shared') &gt;&gt;&gt;share &lt;bound method MyService.exposed_get_shared of &lt;__main__.MyService object at 0x011BA698&gt;&gt; &gt;&gt;&gt;share=getattr(conn.root,'get_shared')() &gt;&gt;&gt;share &lt;__main__.SharedClass object at 0x00B6ED30&gt; &gt;&gt;&gt;share.action() i am doing something </code></pre> <p>If i try to do it in a function i am getting an error ;(</p> <pre><code>&gt;&gt;&gt;def returnObject(objName, host, port): ... conn = rpyc.connect(host, port) ... print conn ... attr = getattr(conn.root, 'get_' + objName)() ... print attr ... return attr &gt;&gt;&gt;share=returnObject('shared','localhost',18861) &lt;rpyc.core.protocol.Connection 'conn2' object at 0x0108AAD0&gt; &lt;__main__.SharedClass object at 0x00B6ED30&gt; &gt;&gt;&gt;share Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "C:\Python27\lib\site-packages\rpyc\core\netref.py", line 168, in __repr__ return syncreq(self, consts.HANDLE_REPR) File "C:\Python27\lib\site-packages\rpyc\core\netref.py", line 69, in syncreq return conn().sync_request(handler, oid, *args) AttributeError: 'NoneType' object has no attribute 'sync_request' </code></pre> <p>My purpose is to have an object initialized in server and to have many client access it. The initialized class is thread safe and so multiple clients can use it.</p> <p>I realize that i am missing something while doing this.</p> <p>--</p> <p>Adhithya</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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