I want to use a python module that is accessible on a remote rpyc server only. Is there a difference between the following two ways of accessing modules on a remote machine:
""" on the client side: """
my_local_mod_ref = my_rpyc_connection.root.getmodule("remote_module_name")
my_local_mod_ref = my_rpyc_connection.root.a_func_returning_the_module_ref()
""" on the server side: """
def exposed_a_func_returning_the_module_ref()
import my_remote_module_name
return my_remote_module_name
If there is a difference, which of the two alternatives is cleaner or preferable?
Here is the implementation of this getmodule
:
def exposed_getmodule(self, name):
"""imports an arbitrary module"""
return __import__(name, None, None, "*")
As you can see, if the module is not already loaded in the server, calling getmodule
imports it, and (either way) a netref to the object module is returned.
If this matches the behavior of your a_func_returning_the_module_ref()
, then there's no difference.
I'd guess getmodule
is provided out-of-the-box, for being very useful, so you don't have to define it (or something similar) explicitly in order to achieve this goal.