具有并发请求的 Python XMLRPC
我正在寻找一种方法来防止多个主机向 Python XMLRPC 侦听器同时发出命令。侦听器负责运行脚本以在该系统上执行任务,如果多个用户尝试同时发出这些命令,这些任务将会失败。有没有办法可以阻止所有传入请求,直到单个实例完成?
I'm looking for a way to prevent multiple hosts from issuing simultaneous commands to a Python XMLRPC listener. The listener is responsible for running scripts to perform tasks on that system that would fail if multiple users tried to issue these commands at the same time. Is there a way I can block all incoming requests until the single instance has completed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为 python SimpleXMLRPCServer 模块就是你想要的。我相信该模型的默认行为是在处理当前请求时阻止新请求。默认行为给我带来了很多麻烦,我通过在 ThreadingMixIn 类中混合来更改该行为,以便我的 xmlrpc 服务器可以同时响应多个请求。
如果我正确理解你的问题,SimpleXMLRPCServer 就是解决方案。直接使用就可以了。
I think python SimpleXMLRPCServer module is what you want. I believe the default behavior of that model is blocking new requests when current request is processing. The default behavior gave me lots of trouble and I changed that behavior by mix in ThreadingMixIn class so that my xmlrpc server could respond multiple requests in the same time.
If I understand your question correctly, SimpleXMLRPCServer is the solution. Just use it directly.
能有其他沟通渠道吗?如果是,则在服务器和客户端之间运行“轮到我时给我回电话”协议。
换句话说,每个客户端都会注册其向服务器发出请求的意图,并且所述服务器会在准备好时“回调”下一个客户端。
Can you have another communication channel? If yes, then have a "call me back when it is my turn" protocol running between the server and the clients.
In other words, each client would register its intention to issue requests to the server and the said server would "callback" the next-up client when it is ready.
有几种选择:
SimpleXMLRPCServer
)来处理后续请求。threading.Lock()
。lockfile
模块或GET_LOCK()
函数)。There are several choices:
SimpleXMLRPCServer
to process requests subsequently.threading.Lock()
in threaded server.lockfile
module orGET_LOCK()
function in mysql) in multiprocess server.