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     <http://www.facebook.com/tomerfiliba>
<http://il.linkedin.com/in/tomerfiliba>


On Tue, Apr 30, 2013 at 12:24 PM, Prashant Shewale <[email protected]>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 [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to