本文介绍了具有并发请求的 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?

推荐答案

我认为 python SimpleXMLRPCServer 模块就是你想要的.我相信该模型的默认行为是在处理当前请求时阻止新请求.默认行为给我带来了很多麻烦,我通过在 ThreadingMixIn 类中混合来更改该行为,以便我的 xmlrpc 服务器可以同时响应多个请求.

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.

class RPCThreading(SocketServer.ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
    pass

如果我正确理解您的问题,SimpleXMLRPCServer 就是解决方案.直接用就行了.

If I understand your question correctly, SimpleXMLRPCServer is the solution. Just use it directly.

这篇关于具有并发请求的 Python XMLRPC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 18:34