python RPyC 用户数

Gre*_*uhn 5 python rpyc

我希望使用 RPyC 为硬件板提供 API 作为服务。该板一次只能满足一个用户的需求。有什么办法可以让 RPyC 强制执行一次只有一个用户可以访问吗?

shx*_*hx2 2

我不确定这是否有效(或工作良好),但您可以尝试在循环内启动 OneShotServer ,因此在任何给定时刻仅提供一个连接。当连接关闭时,服务器终止,并且您为下一个客户端启动另一个连接。

就像是:

is_aborting = False
while not is_aborting:
    server = OneShotServer(myservice, *args, **kwargs)
    # serve the next client:
    server.start()
    # done serving the client
Run Code Online (Sandbox Code Playgroud)

如果这不起作用,最好的选择是继承ThreadedServer,并重写_accept_method方法来跟踪是否已打开连接,如果有则返回错误。