Skip to main content
 首页 » 编程设计

python之在 rpyc python 中传递类方法

2025年05月04日8bluestorm

我见过使用 teleport_function 传递函数,有什么方法可以传递类方法吗??或者我能否以任何其他方式远程执行我的类对象

我可以通过将类作为一项服务来解决这个问题。但这并不能完全满足我在项目中的要求。

请您参考如下方法:

import rpyc 
from rpyc.utils.classic import teleport_function 
 
def a(test): 
    print test 
 
if __name__ = '__main__': 
    proxy = rpyc.classic.connect('remte.com') 
    launch_command_remote = teleport_function(proxy, a) 
    launch_command_remote("Voila") # Executed remotly