Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:18:55+00:00 2026-05-29T04:18:55+00:00

I have a remote server like below which already has an initialized class and

  • 0

I have a remote server like below which already has an initialized class and i have set protocol config as allow public attrs True.

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()

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

**Client**

**Direct connection**

>>>Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
>>>Type "help", "copyright", "credits" or "license" for more information.
>>>conn=rpyc.connect('localhost',18861)
>>>share=getattr(conn.root,'get_shared')
>>>share
<bound method MyService.exposed_get_shared of <__main__.MyService
object at 0x011BA698>>
>>>share=getattr(conn.root,'get_shared')()
>>>share
<__main__.SharedClass object at 0x00B6ED30>
>>>share.action()
i am doing something

If i try to do it in a function i am getting an error ;(

>>>def returnObject(objName, host, port):
...    conn = rpyc.connect(host, port)
...    print conn
...    attr = getattr(conn.root, 'get_' + objName)()
...    print attr
...    return attr
>>>share=returnObject('shared','localhost',18861)
<rpyc.core.protocol.Connection 'conn2' object at 0x0108AAD0>
<__main__.SharedClass object at 0x00B6ED30>
>>>share
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 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'

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.

I realize that i am missing something while doing this.

—

Adhithya

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:18:57+00:00Added an answer on May 29, 2026 at 4:18 am

    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.

    >>> import rpyc
    >>> def returnObject(objName, host, port):
    ...     conn = rpyc.connect(host, port)
    ...     print conn
    ...     attr = getattr(conn.root, 'get_' + objName)()
    ...     print attr
    ...     return conn, attr
    ... 
    >>> conn, share = returnObject('shared', 'localhost', 18861)
    <rpyc.core.protocol.Connection 'conn1' object at 0x10b0676d0>
    <__main__.SharedClass object at 0x1091ff790>
    >>> share
    <__main__.SharedClass object at 0x1091ff790>
    >>> share.action()
    

    As I am involved in development of another python remote-object solution Versile Python, 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:

    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()
    

    Client code to access the service:

    >>> from versile.quick import *
    >>> VSEResolver.add_imports()
    >>> gw = VUrl.resolve('vtp://localhost/')
    >>> shared = gw.get_shared()
    >>> shared._v_activate() # required for activating as remote-python proxy
    >>> shared.action()
    u'I am doing something'
    >>> gw._v_link.shutdown()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a remote server that has win2003 installed I can connect to the
I have a remote actor (client) which is registering with another remote actor (server)
I have a folder on my remote server that has a few .png files
I have a script which logs on to a remote server and tries to
I'm developing an enterprise-like application that fetches data from a remote server. I have
I have some json from a remote server and the results are returned like
I know the app servers like Websphere and Weblogic have remote deployment capabilities that
I have a remote server that hosts my subversion repository on a non-standard ssh
I have a script that retrieves objects from a remote server through an Ajax
I have some code that downloads an image from a remote server $data =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.