python RPyC 用户数

python RPyC user count

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

我不确定这是否有效(或有效),但您可以尝试在循环中启动 OneShotServer,这样在任何给定时刻都只提供一个连接。当连接关闭时,服务器终止,你为下一个客户端启动另一个。

类似于:

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

如果这不起作用,最好的办法是子类化 ThreadedServer, and override the _accept_method 方法以跟踪是否已打开连接,如果存在则 return 出错。