具有并发请求的 Python XMLRPC

发布于 2024-08-08 09:59:03 字数 120 浏览 3 评论 0原文

我正在寻找一种方法来防止多个主机向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

软的没边 2024-08-15 09:59:03

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

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

如果我正确理解你的问题,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.

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

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

ぃ双果 2024-08-15 09:59:03

能有其他沟通渠道吗?如果是,则在服务器和客户端之间运行“轮到我时给我回电话”协议。

换句话说,每个客户端都会注册其向服务器发出请求的意图,并且所述服务器会在准备好时“回调”下一个客户端。

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.

我乃一代侩神 2024-08-15 09:59:03

有几种选择:

  1. 使用单进程单线程服务器(例如 SimpleXMLRPCServer)来处理后续请求。
  2. 在线程服务器中使用threading.Lock()
  3. 您可以在多进程服务器中使用一些外部锁定机制(例如mysql中的lockfile模块或GET_LOCK()函数)。

There are several choices:

  1. Use single-process-single-thread server like SimpleXMLRPCServer to process requests subsequently.
  2. Use threading.Lock() in threaded server.
  3. You some external locking mechanism (like lockfile module or GET_LOCK() function in mysql) in multiprocess server.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文