我想使用只能在远程 rpyc 服务器上访问的 python 模块。以下两种访问远程计算机上模块的方式有区别吗:
客户端的“”“:”“”
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()
"""在服务器端:"""
def exposed_a_func_returning_the_module_ref()
import my_remote_module_name
return my_remote_module_name
如果存在差异,这两种选择中哪一种更干净或更可取?
最佳答案
这里是这个getmodule
的实现:
def exposed_getmodule(self, name):
"""imports an arbitrary module"""
return __import__(name, None, None, "*")
如您所见,如果该模块尚未加载到服务器中,则调用 getmodule
会导入该模块,并且(无论哪种方式)都会返回对象模块的 netref。
如果这与您的 a_func_returning_the_module_ref()
的行为匹配,则没有区别。
我猜 getmodule
是开箱即用的,非常有用,因此您不必显式定义它(或类似的东西)来实现此目的目标。
关于python - rpyc: root.getmodule ("module_name")和手动返回模块引用之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31388872/