正如here所解释的,使用RPyC 2重定向stdio/stdin非常简单。这意味着在服务器中执行的“打印”命令将在客户端显示打印的字符串。
正如here解释的那样,RPyC 2是不安全的,不推荐使用,但我找不到如何使用RPyC 3在客户端打印。
有谁知道如何做到这一点吗?
编辑:
例如,这是我的服务器的代码:
import rpyc
import time
from rpyc.utils.server import ThreadedServer
class TimeService(rpyc.Service):
def exposed_print_time(self):
for i in xrange(10):
print time.ctime()
time.sleep(1)
if __name__ == "__main__":
t = ThreadedServer(TimeService, port=8000)
t.start()在我的客户端中,我运行:
conn = rpyc.connect("192.168.1.5")
conn.root.print_time()我的目标是在客户机的stdout中获取每秒(或我想要打印的任何东西)的时间,但是客户机挂起了,并且时间只在服务器中打印。
发布于 2021-10-09 17:43:04
您可以在服务器端使用return:
#on server
def exposed_test(self):
return "this is test"
#on client
conn.root.test()
>>> 'this is test'https://stackoverflow.com/questions/23478450
复制相似问题