Question: I am quite new to python and I am trying to write a simple implementation of REST api calls. My goal is to be able to create methods of a class at run time and to be able to use method names as basis for API calls. For example list\_virtual\_networks will turn into GET to <http://localhost:8080/virtual-networks>, etc. I'd also want to practice at some more advanced object oriented techniques. Here's my approach:

```
def _api_call_wrapper(wrapped_function):
    def wrapper_function(*args, **kwargs):
        handler_name = wrapped_function.__name__
        agent_logger.info('Got function name {}'.format(handler_name))
        <do something>
        return res
return wrapper_function

class API(HTTPConnection):
    def __init__(self, host, port):
        <do something>

    def __getattr__(self, name):
    @_api_call_wrapper
    def handler(self, *args, **kwargs):
        self.request('GET', self.last_url)
        return self.getresponse()
    handler.__name__ = name
    setattr(self, name, handler)
    agent_logger.info('Returning method with name {}'.format(self.name))

if __name__ == '__main__':
    api = API(127.0.0.1, 8080)
    api.list_virtual_networks()

```

Here's what I see in logs:

2016-12-08 23:05:03,034 - AgentLogger - INFO - Returning method with name function wrapper\_function at 0x1073c8d70>

2016-12-08 23:05:03,034 - AgentLogger - INFO - Returning method with name None

I hope I made myself clear enough to explain what I wanted to achieve. Is there a way to solve it at least roughly in a way I am trying to do it?

Answer: 
Your synchronization is broken, so you can't deduce much by your experiment. Each time you do `sum += i`, you assign a new Integer to `sum`. So the threads synchronize on two different Integers. 

Also, you're binding an instance of Sommatore, but you're showing the code of Adder. 

But to answer your question, you're binding an instance, and RMI won't magically create copies of that instance. It won't synchronize all calls to this instance either. So you need to make sure the code is thread-safe. Just because a quick test produces a correct result despite the absence of proper synchronization doesn't mean that it will always be that way. You can cross a road with your eyes shut 10 times and never die. That doesn't mean it's safe.
> 
> Is RMI automatically "thread-safe"?
> 
> 
> 

No.

> 
> Extra question: when I bind an object in RMI, what exactly am I binding? The specific instance of the object I call Naming.rebind() on, or the class(and then when I look it up I just get a new instance?)?
> 
> 
> 

Actually neither. You are binding a *stub*, which is irretrievably associated with the remote object instance you supplied to the `bind()` method.