pythonrpyc

Return object by value (not as Netref) from RPyC service exposed method


I'm using an RPyC Service to make some calculations on a remote machine and then want to return the result, which is a numpy array to the user - the rpyc client. The return value of the service method is Netref to a numpy array, and therefore, when it returns to the client, he can not use operations such as np.mean(return_arr) on the returned array (even after using 'allow_all_attr':True).

I am aware that I can obtain the return_arr using the rpyc obtain method on the client side, but I want to leave the client code (almost) empty for internal project reasons.

So, is there a way to configure the Service/ method to return the numpy arrays by value instead of netref?


Solution

  • Possible solution: Send the client's numpy library to the service and save it as self.client_np.

    Then, whenever you want to return numpy array from a servive method to the client just use: return self.client_np.array(return_arr)