Re: [rpyc] weakly-referenced object no longer exists

609 views
Skip to first unread message

Tomer Filiba

unread,
Apr 30, 2013, 5:57:26 AM4/30/13
to rpyc
you lose the connection: netrefs hold a weakref to their connection, so they won't keep it alive unnecessarily.
in your class, you create a new connection each time, which terminates as soon as the function returns.
it's a bad idea to create many connections anyway. instead, create a single, global connection, and it will work.

e.g.,

g_conn = rpyc.classic.connect("localhost")

class WrapperClass:
    def __new__(cls, *args, **kwargs):
         return g_conn.modules[mypath.mymodule.MyClass'].MyClass()

btw, it seems your WrapperClass can be just turned into a function. 
be sure to watch http://www.youtube.com/watch?v=o9pEzgHorH0 - he raises some good points there


hope this solves you issue,
-tomer


-----------------------------------------------------------------
    
Tomer Filiba 
tomerfiliba.com        


On Tue, Apr 30, 2013 at 12:24 PM, Prashant Shewale <pvsh...@gmail.com> wrote:
Hi,

     I am quite new to using RPyC. For my test framework I am trying to create a generic local wrapper class which will actually return me netref class instance of remote machine. For this I am trying to override __new__ method of my wrapper class. What I am trying is as below (in code below I have hardcoded things, but eventually I want to generalize it using parameters)

import rpyc

class WrapperClass:
    def __new__(cls, *args, **kwargs):
         conn = rpyc.classic.connect('localhost')
         _new_instance = conn.modules[mypath.mymodule.MyClass'].MyClass()
         return _new_instance

But I use this wrapper class, I can create netref instace of MyClass, but if I call __dir__ on that to list attributes, it gives me error like ReferenceError: weakly-referenced object no longer exists

Can somebody please let me know what is going wrong.

Thanks,
Prashant


--
 
---
You received this message because you are subscribed to the Google Groups "rpyc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rpyc+uns...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Prashant Shewale

unread,
Apr 30, 2013, 8:23:59 AM4/30/13
to rp...@googlegroups.com
Thanks for quick reply. Global connection worked great.

Artem Chekunov

unread,
Nov 18, 2014, 3:59:56 AM11/18/14
to rp...@googlegroups.com
Hi,

i have a similar problem
but i can't use global connection, because i need keep several connection in one time

could do you say me, how to should i create connection for each thread?
Reply all
Reply to author
Forward
0 new messages